Comments (8)
Wow, this is really strange!
I can reproduce the error on Linux using Python 2.
With Python 3, however, it works. Except the Python interpreter crashes at the end of the script, see #1.
When using play()
in a script, you should make sure that the script doesn't end before the playback is finished (with blocking=True
or stop()
or wait()
).
I have no clue what causes that problem, any ideas or further clues would be highly appreciated!
from python-sounddevice.
same problem on windows 7 with python 2.7
from python-sounddevice.
if the sound is played from within a class, it works (it doesn't make any sense to me, however..; python2.7, debian-unstable)
minimal example, which works:
main.py:
import module2
a = module2.TEST()
a.play()
module2.py:
import module1
snd = module1.Sound('startle50ms.wav')
#snd.play() wouldn't work but, when played from within a class, it's ok..
class Test(object):
def __init__(self):
self.x = None
def play(self):
snd.play()
module1.py:
import time
class Sound(object):
def __init__(self, filename):
self._sd = __import__('sounddevice')
self._sf = __import__('soundfile')
self.data, self.fs = self._sf.read(filename)
def play(self):
self._sd.play(self.data, self.fs)
print 'sound played'
time.sleep(1)
#self._sd.wait()
this doesn't work:
main2.py:
import module3
module3.py:
import time
class Sound(object):
def __init__(self, filename):
self._sd = __import__('sounddevice')
self._sf = __import__('soundfile')
self.data, self.fs = self._sf.read(filename)
def play(self):
self._sd.play(self.data, self.fs)
print 'sound played'
time.sleep(1)
#self._sd.wait()
snd = Sound('startle50ms.wav')
snd.play()
from python-sounddevice.
a more simple (working) example:
main.py:
import modulex
a = modulex.Test()
a.play()
modulex.py
import sounddevice as sd
import soundfile as sf
data, fs = sf.read('startle50ms.wav')
class Test(object):
def play(self):
sd.play(data, fs, blocking=True)
from python-sounddevice.
Still very strange, still no clue ...
It seems that playback doesn't work (on Python 2) during the import process. Once the import is done, it works again.
I don't know what's the reason for this, but you shouldn't have done that in the first place.
You should define a function in your module and then call it after (not during) importing the module.
Independent of the current issue, you would get a problem if you want to run the code in the module twice, since the module object is cached and it's content is only executed on the first import. On further imports, nothing will happen.
from python-sounddevice.
Probably related to this error. I have the same problem but with the playrec() function.
The weird thing is that i get in two situations two different results.
module.py
:
import numpy as np
def simplefiedPlayRec(data, samplerate=None, input_channels=None, output_channels=None,
repeats=None):
try:
import sounddevice as sd
data = np.tile(data, repeats)
data = np.repeat(data, output_channels).reshape((len(data), output_channels))
print(np.shape(data))
recarray = sd.playrec(data, samplerate)
sd.wait()
recarray = np.sum(np.array_split(recarray, repeats, axis=0))
recarray /= repeats
return(recarray)
except ImportError:
raise("No module named 'sounddevice'. ")
and main.py
:
from module import simplefiedPlayRec # optional
import numpy as np
T = 5
fs = 44100
t = np.arange(T*fs) / fs
signal = np.sin(2*np.pi*440*t)
rec = simplefiedPlayRec(signal, fs, output_channels=2, repeats=3)
if i load the module from another file. no sound; no recording and no error.
when signal running in the same file (so no import) i have no sound no reording but an error.
it is this one
TypeError: Unable to determine number of input channels
from python-sounddevice.
@Jee-Bee Thanks for your comment.
The TypeError
you are mentioning is legitimate, you have to specify the number of input channels, see the docs.
Apart from that I cannot say anything, because your code is much to complicated.
You should remove all the tiling, repeating and splitting, just reducing it to the bare minimum.
Once you have done that, we can start digging for errors ...
from python-sounddevice.
This has probably something to do with Pythons import lock ...
There may be a way around this, but as I said above (#38 (comment)), playback/recording shouldn't be done during an import anyway.
So it is probably actually good that it doesn't work ...
from python-sounddevice.
Related Issues (20)
- Raspberry pi: sounddevice query_devices() does not see usb devices HOT 2
- check_input_settings does not raise exception for some unsupported sample rates on macOS HOT 4
- Cannot get aggregate device to work with sounddevice/rtmixer signal processing.py example HOT 1
- Enhancement Request: Integrate Playback Status Check into Simple `play`/`stop` API in `sounddevice` HOT 4
- Feature request for loopback of output device. HOT 3
- 设备解码错误?utf-8' codec can't decode byte 0xc2 in position 6: invalid continuation byte HOT 4
- Sounddevice + big dict + OOP = Segfault / Bus Error HOT 11
- Update device list by reloading portaudio dll HOT 1
- Won't be able to import sounddevice due to unknown issue with `libportaudio64bit.dll` HOT 5
- Error opening OutputStream: Unanticipated host error', -9999, (2, 0, 'Failed to load ASIO driver
- Use sounddevice with virtual audio device and minimize latency HOT 1
- Achieving stable latency between calls of "playrec" HOT 8
- sounddevice not recognize all devices?
- Issues with playing concurrently with Youtube HOT 1
- Latency 30mSec HOT 9
- Advice on asynchronous playback HOT 7
- docker node minimal image
- Can I continue recording until the volume drops below a threshold? HOT 4
- Simultaneous audio playback datatype issue HOT 2
- Does sd.wait() block all other threads? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-sounddevice.