spatialaudio / python-sounddevice Goto Github PK
View Code? Open in Web Editor NEW:sound: Play and Record Sound with Python :snake:
Home Page: https://python-sounddevice.readthedocs.io/
License: MIT License
:sound: Play and Record Sound with Python :snake:
Home Page: https://python-sounddevice.readthedocs.io/
License: MIT License
I'm attempting to "freeze" an application into a distributable OS X .app using py2app. I have slimmed my code down to the bare minimum which triggers this issue, but I don't understand enough of the magic to determine if the problem is truly with sounddevice, CFFI, py2app, or my configuration. Apologies if this is the wrong channel to start looking for a fix!
Once frozen, a simple import sounddevice
causes the blowup. The exception is thrown when a C header is fed to CFFI as a giant string literal:
Traceback (most recent call last):
File "sdtest/dist/sdtest.app/Contents/Resources/__boot__.py", line 77, in <module>
_run()
File "sdtest/dist/sdtest.app/Contents/Resources/__boot__.py", line 62, in _run
exec(compile(source, path, 'exec'), globals(), globals())
File "sdtest/dist/sdtest.app/Contents/Resources/sdtest.py", line 1, in <module>
import sounddevice
File "sounddevice.pyc", line 313, in <module>
File "cffi/api.pyc", line 105, in cdef
File "cffi/api.pyc", line 119, in _cdef
File "cffi/cparser.pyc", line 299, in parse
File "cffi/cparser.pyc", line 304, in _internal_parse
File "cffi/cparser.pyc", line 260, in _parse
File "cffi/cparser.pyc", line 40, in _get_parser
File "pycparser/c_parser.pyc", line 116, in __init__
File "pycparser/ply/yacc.pyc", line 3293, in yacc
File "pycparser/ply/yacc.pyc", line 2938, in validate_all
File "pycparser/ply/yacc.pyc", line 2982, in validate_modules
File "inspect.pyc", line 690, in getsourcelines
File "inspect.pyc", line 538, in findsource
IOError: could not get source code
My setup.py
with py2app configuration is as follows; I've explicitly included the path to my compiled PortAudio lib (which magically installed with sounddevice
) to ensure it is included within the the .app:
from setuptools import setup
PY2APP_OPTIONS = {
'argv_emulation': False,
'includes': ['sounddevice'],
'frameworks': ['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/_sounddevice_data/libportaudio.dylib'],
}
setup(
app=['sdtest.py'],
options={'py2app': PY2APP_OPTIONS},
setup_requires=['py2app'],
)
And the sdtest.py
file itself need only be as simple as this to trigger this problem:
import sounddevice
Can you provide any suggestions as to how better to track down the problem here? I don't really understand what CFFI is doing under the hood, nor understand "who" is unable to find source code nor what source it's looking for.
The docs say
NumPy is only needed if you want to play back and record NumPy arrays.
However, when I try playing a normal python bytes object, the program errors with
ImportError: NumPy must be installed for play()/rec()/playrec().
Is there something I'm missing here? I hope so, because I really like the high-level interface instead of manually wrangling streams with PyAudio. But if the basic functionality isn't available without NumPy, maybe you should make it more explicit in the docs?
Hello,
I am trying to run sounddevice on the beaglebone black board. I use the code below to test feedthrough. However, when the latency is set to low, or the buffer size is small, the program just hangs, rather than dropping a few frames and continuing. There is no error message either. Can I do something about it ?
Thanks you in advance.
import sys
import sounddevice as sd
duration = 10 # seconds
import numpy as np
from scipy.signal import lfilter
sd.default.channels = (2,2)
sd.default.device = (0, 1)
sd.default.samplerate = 48000
sd.default.dtype = ('int16','int16')
sd.default.never_drop_input = False
sd.default.latency = ('low','low')
sd.default.blocksize = 0
def callback(indata, outdata, frames, time, status):
if status:
print(status)
outdata[:] = indata
with sd.Stream(callback=callback):
try:
while True:
sd.sleep(1000)
except KeyboardInterrupt:
print("Interrupted, how rude!")
except Exception:
traceback.print_exc(file=sys.stdout)
sys.exit(1)
Hi, I am trying to create a 'loop pedal' emulator, and I need to start recording audio without a duration already specified. Something like 'record audio until I want'. I dont know how to do that in sounddevice. Is this possible?
When i play lots of ~0.5sec voice files, the system stops working.
In general, i get no error message just the loudspeaker keep silent.
But right now i get this (and i use this to ask for help):
sounddevice.PortAudioError: Invalid stream pointer
The code im using can be seen here (but its similar to the "play_file" example):
https://github.com/LocutusOfPenguin/picochess/blob/master/talker/picotalker.py
As said, this effect is after some "moves" , and each move is around 1-3 small voice files.
Hi,
not quite sure this is the right place to post this issue, but I hope you can help.
I'm running smoothly sounddevice under macos, now I need to make my scripts to work also on Windows.
I have installed cygwin and from there I have installed Python2.7, libffi-devel and portaudio2. The error I get when importing portaudio (in ipython) is this:
In [1]: import sounddevice
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-20b0e45d0855> in <module>()
----> 1 import sounddevice
/usr/lib/python2.7/site-packages/sounddevice.py in <module>()
2530
2531
-> 2532 _ignore_stderr()
2533 _initialize()
2534
/usr/lib/python2.7/site-packages/sounddevice.py in _ignore_stderr()
2518 try:
2519 stdio = ffi.dlopen(None)
-> 2520 devnull = stdio.fopen(_os.devnull.encode(), b'w')
2521 except OSError:
2522 return
/usr/lib/python2.7/site-packages/cffi/api.pyc in __getattr__(self, name)
835 class FFILibrary(object):
836 def __getattr__(self, name):
--> 837 make_accessor(name)
838 return getattr(self, name)
839 def __setattr__(self, name, value):
/usr/lib/python2.7/site-packages/cffi/api.pyc in make_accessor(name)
831 if name not in accessors:
832 raise AttributeError(name)
--> 833 accessors[name](name)
834 #
835 class FFILibrary(object):
/usr/lib/python2.7/site-packages/cffi/api.pyc in accessor_function(name)
776 value = backendlib.load_function(BType, name)
777 except KeyError as e:
--> 778 raise AttributeError('%s: %s' % (name, e))
779 library.__dict__[name] = value
780 #
AttributeError: fopen: "function 'fopen' not found in library '<None>': No such process"
thanks for your help.
d
When using WASAPI shared mode in Windows, it is necessary to match the samplerate in sounddevice
and Control Panel > Sound > device > Properties > Advanced tab > Default Format.
In sounddevice v0.3.5, a samplerate mismatch throws an exception "sounddevice.PortAudioError: Error opening RawOutputStream: Invalid device".
I propose to instead detect the mismatch to the device default samplerate and clarify the exception message. This will better help users understand and fix this type of problem. Often, they will want to change the Windows setting.
When I run on OS X 10.11.1 sd.play(x, fs)
I get the next warning. Does it have to do only with sounddevice? Is there a way to remove it?
WARNING: 140: This application, or a library it uses, is using the deprecated Carbon Component Manager for hosting Audio Units. Support for this will be removed in a future release. Also, this makes the host incompatible with version 3 audio units. Please transition to the API's in AudioComponent.h.
Hi,
I'm confused about the play() function in this library. in the documentation, it says it returns immediately, but for me, it seems to start, wait for the playback to finish, and then return. Why is this happening/has it been changed?
Use case: two devices with m and n channels (in and/or out). I want to use the channels of both (m+n) to output and/or record.
Is this possible?
The real use case is less weird than this, I'm on windows and WDM is splitting a multichannel interface into several separated interfaces.
ps: And yes: asio would solve the problem, but I'm under cygwin and cygwin's portaudio doesn't have asio support apparently. There are other solutions, like using conda/anaconda, there it works. Anyway I think the question still makes sense.
Hello,
it's not an issue, but rather a question.
Is it possible to enable exclusive for wasapi?
best wishes
Piotr
I've compiled portaudio myself (with Visual C++ 2008 Express Edition), and tried out binaries from https://github.com/adfernandes/precompiled-portaudio-windows but there is no sound on win 8.1, when using wdm/ks...
any ideas how to get around it?
See https://subversion.assembla.com/svn/portaudio/portaudio/trunk/qa/loopback/README.txt
With a bit of luck this can be used with the JACK dummy backend as an automated test on http://travis-ci.org ...
On a german Windows 7 machine with sounddevice 0.3.3, I get a traceback (see below) when I call:
python -m sounddevice
The reason seems to be that a german Windows version has non ASCII characters in the device name.
(e.g.: 'Primärer Soundaufnahmetreiber').
Possible Solution:
Line 1806:
Change
name=info['name'],
To:
name=repr(info['name']),
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Python27\lib\site-packages\sounddevice.py", line 2536, in <module>
print(query_devices())
File "C:\Python27\lib\site-packages\sounddevice.py", line 1810, in __repr__
for idx, info in enumerate(self))
File "C:\Python27\lib\site-packages\sounddevice.py", line 1810, in <genexpr>
for idx, info in enumerate(self))
UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 18: ordinal not in range(128)
Hi,
I'm trying to write an application where I can stream the input of one device over a websocket for all the connected clients.
Currently I have everything set up so I can broadcast out the base64 encoded bytes returned by either sounddevice.InputStream
or sounddevice.RawInputStream
as they are returned by their callback. Currently this looks like:
@classmethod
def handle_input_buffer(cls, data, frames, time, status):
message = b64encode(data.copy().tostring())
cls.broadcast(message)
Obviously broadcasting a stringified version of a numpy array doesn't make sense if the clients aren't Python clients. Would anyone be able to suggest what kind of format I should best send this out in - so it can be serialized by clients?
Thanks
This is actually two issues that I have when doing full-duplex streaming using my own callback function:
I wanted to make sure that the over/underflow flags were indeed set when my callback function was too slow but it doesn't seem to be working. To simulate this, I just put a time.sleep(1)
inside the callback, but no error was raised and none of the callback flags are set on the next callback. Do you have any code that tests this functionality indeed works as intended?
I tried setting the prime_output_buffers_using_callback parameter, but my callback function never gets a call where status.priming_output
is true. I'm using full duplex streaming, is there any other reason why this option might be ignored? Have you tested this option?
Mostly, those messages are annoying, but I don't know if they ever show useful information.
We could try to redirect the standard output from PortAudio to os.devnull
, as shown here:
http://eli.thegreenplace.net/2015/redirecting-all-kinds-of-stdout-in-python/
http://stackoverflow.com/questions/5081657/how-do-i-prevent-a-c-shared-library-to-print-on-stdout-in-python
Using friture-git I've encountered this issue:
File "/usr/lib/python3.5/site-packages/sounddevice.py", line 1069, in time
raise PortAudioError('Error getting stream time')
sounddevice.PortAudioError: Error getting stream time
I'm using sounddevice 0.3.6 (which magically pulled in PortAudio V19.6.0-devel) on Mac OS X 10.9.5 with python.org Python 2.7.12.
When I stop()
a blocking play()
from another thread, I see the following message on stderr:
||PaMacCore (AUHAL)|| Error on line 2754: err='-50', msg=Unknown Error
The following example code triggers this error:
import time
from threading import Thread
from scipy.io import wavfile
import sounddevice
class AudioThread(Thread):
def __init__(self, fname):
Thread.__init__(self)
self.fname = fname
def run(self):
samplerate, signal = wavfile.read(self.fname)
sounddevice.play(signal, samplerate, blocking=True)
def stop(self):
sounddevice.stop()
thread = AudioThread('test.wav')
thread.start()
time.sleep(1)
thread.stop()
Calling stop()
on a non-blocking play()
from the same thread does not produce an error.
Hi, on windows when I have devices that have polish characters in the module's name, it crashes:
>>> import sounddevice as sd
>>> sd.query_devices()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\admin_000\AppData\Roaming\Python\Python27\site-packages\sounddevice.py", line 1887, in __repr__
return text.encode(_sys.stdout.encoding or 'utf-8')
File "C:\Python27\lib\encodings\cp852.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u2014' in position 77: character maps to <undefined>
>>> sd.query_devices()
Exception KeyboardInterrupt in <module 'threading' from 'C:\Python27\lib\threading.pyc'> ignored
To fix this, I had to change in sounddevice.py
line:
return text.encode(_sys.stdout.encoding or 'utf-8')
to:
return text.encode('utf-8')
Hi,
I am encountering an issue where all my recordings start with silence.
When I record with a WASAPI device the silence usually lasts 255 samples whereas ASIO device recordings starts with 512 samples of silence i.e. the value 0
I use the following small snippet to record the audio.
import sounddevice as sd
from scipy.io import wavfile
import numpy as np
import begin
@begin.start(auto_convert=True)
def main(sound_device: 'Sound Device Name' = 'DMX 6Fire ASIO',
channel_map: 'Channel Mapping' = [1,2],
duration : 'Duration of recording' = 1,
out_file: 'Wavfile to save recording in' = 'out.wav'):
dev = sd.query_devices(sound_device)
sd.default.device = sd._get_device_id(sound_device, None)
sd.default.samplerate = int(dev['default_samplerate'])
print('Starting Recording')
channel_map = [int(c) for c in channel_map]
rec = sd.rec(duration * int(dev['default_samplerate']), mapping=channel_map)
sd.wait()
print('Silent samples', [rec.shape[0] - np.count_nonzero(rec[:,n]) for n in range(rec.shape[1])])
wavfile.write(out_file, int(dev['default_samplerate']), rec)
sounddevice seems to block input()
from printing text. Here's a simple repro:
import sounddevice as sd
name = input("Enter your name: ")
print ("your name is " + name)
When I comment out the first line it works as expected, but with the sounddevice
import it doesn't print anything to the console. I've tried this:
import sys
sys.stdout.flush()
but that doesn't fix the issue. Anyone else having this problem or know how to fix it? I'm using Python 3.6.
On Windows (especially in laptops) original DirectShow audio device name is not unique:
sd.query_devices()
...
0 Microsoft Sound Mapper - Input, MME (2 in, 0 out)
> 1 Микрофон (Устройство с поддержк, MME (2 in, 0 out)
2 Микрофон (Устройство с поддержк, MME (2 in, 0 out)
3 Линия (Elgato Sound Capture), MME (2 in, 0 out)
4 Microsoft Sound Mapper - Output, MME (0 in, 2 out)
< 5 Динамики (Устройство с поддержк, MME (0 in, 2 out)
6 Primary Sound Capture Driver, Windows DirectSound (2 in, 0 out)
Name for device 1 (enabled mic) same as for device 2 (disabled mic).
It will be great to get somehow unique "Alternative name" for devices
(In particulary I try to get this name for default device).
[dshow @ 00000193d788a8a0] "Микрофон (Устройство с поддержкой High Definition Audio)"
[dshow @ 00000193d788a8a0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{A63B8A2D-19F7-4D35-AFA7-0C750E7B6595}"
[dshow @ 00000193d788a8a0] "Микрофон (Устройство с поддержкой High Definition Audio)"
[dshow @ 00000193d788a8a0] Alternative name "@device_cm_{33D9A762-90C8-11D0-BD43-00A0C911CE86}\wave_{293B27B7-BDD1-4B42-
Hello,
I am using sounddevice in a virtual machine running Ubuntu 14.04 LTS. When I import sounddevice I get the next three messages (the application works anyway!):
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
I realized that if start jack before I run my python program these messages disappear. But then I obviously need to stop jack afterwards.
Do you know if there is way to do this from within my python script? I tried something similar to what you suggested me here #10 (comment) but instead I get this error when the program finishes:
python: src/hostapi/jack/pa_jack.c:820: Terminate: Assertion `err == 0' failed.
Aborted (core dumped)
Is this https://jackclient-python.readthedocs.org/en/0.4.0/ for that purpose?
Again, I am just a n00b so I would appreciate your help!
t=10
Fs=48000.0
x=np.linspace(0.0, t, Fs*t)
y=np.sin(1000*2.0*np.pi*x)
myrecording = sd.playrec(y, Fs, channels=2, blocking=True)
sd.playrec()
worked fine with my previous USB sound card, but it makes crackling noises with my new Asus Xonar U7 card. I thought it might be an issue with the sound card and RPI and not specifically the sounddevice
package, but playing wav files with aplay
is without crackling so I don't know. Is there any way to fix this?
So I am trying to output an impulse on a particular channel of a large sound card (not the same channel each time) I found Sounddevice very useful however I get some strange issues when mapping my sample to channel one only which doesn't happen with any other mapping. The following command:
sd.play(impulse.samples, samplerate=96000, mapping=[1])
appears to output on both channels one an two when I expect audio on just channel 1 while
sd.play(impulse.samples, samplerate=96000, mapping=[2])
outputs on channel 2 as expected and all other channels I have tested appear to work as channel 2 does. Even
sd.play(impulse.samples, samplerate=96000, mapping=[1, 3])
outputs on channels 1 and 3 as I expect. I am not ruling out that i am missing something but I would appreciate some help very much.
Just incase you need it i have checked the impulse samples, dtypes and they all appear to be correct
Thanks.
This is a minor annoyance. Not worth fixing if it delays the sounddevice release for the next WinPython release.
Problem: With the WDM-KS and ASIO host API devices are used for the same USB external DAC, sd.default.extra_settings = sd.WasapiSettings(exclusive=False)
and sd.default.extra_settings = sd.WasapiSettings(exclusive=True)
cause sd.RawOutputStream()
to raise an exception. Without sd.default.extra_settings
, these host APIs play fine.
I would like to set sd.default.extra_settings = sd.WasapiSettings(exclusive=True)
as my normal default. It is not intuitive to me that WASAPI settings should cause an exception for WDM-KS and ASIO host API devices. I expect WDM-KS and ASIO host API devices to ignore WASAPI settings.
How is the amplititude defined when using float dtypes?
I first thought it would be normalized in [-1, 1] but scaling to [-2, 2] increased the volume.
First off, thanks for developing this! PyAudio is kind of incomplete and seems to be pretty inactive so I'm really glad to see this project getting off the ground.
Anyway, I'm pretty new to this library so forgive me if I missed something but I can't seem to find any support for making arbitrary length recordings. So, did I miss something? And if not, do you have any plans to add this functionality in the near future?
Examplecode:
import numpy as np
import time
import sounddevice as sd
def FindFreq_Resp(f_num, Amp):
print "Calculating frequency response..."
Freq=np.logspace(1.3, 4.3, num=f_num)
for f in Freq:
xx=np.linspace(0.0, 1, 48000)
y=Amp*np.sin(f*2.0*np.pi*xx)
myrecording = sd.playrec(y, 48000, channels=1, blocking=True)
Fs=48000
FindFreq_Resp(100,0.1)
print "Some memory has been eaten"
FindFreq_Resp(100,0.1)
print "Even more memory has been eaten"
FindFreq_Resp(100,0.1)
print "Not much memory left :("
If I run the function FindFreq_Resp enough time, the program will run out of swap memory and freeze indefinitely. Why does this happen?
I tried pip install sounddevice
then importing it, on 64 bit windows with 64 bit python - and it wasn't happy..
C:\Users\stu\Desktop\planar>python
Python 2.7.10rc1 (default, May 10 2015, 18:50:04) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import sounddevice
Assertion failed!
Program: C:\Python27\python.exe
File: src/hostapi/wdmks/pa_win_wdmks.c, Line 1035
Expression: FALSE
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
What kind of timestamps are passed to the callback?
When I print them there are only 4 digits before the decimal point.
Hi,
i have a strange problem, but i cant see how to come closer to the cause.
I use two (software) systems: yours and pydub see: https://github.com/jiaaro/pydub
And i have two hardware systems: one is Ubuntu 16.04 and the other a Jessie for RaspPi(3).
If i let sounddevice play a ogg fiel on Rasp, it works. But it fails on ubuntu (i hear noise).
If i do the same with pydub no problem with Ubuntu and on RaspPi , its in worse quality (not useful, but i can guess the voice file - whereas on first, its just noise).
Jürgen
$ python3 -m pip install sounddevice --user
Downloading/unpacking sounddevice
Downloading sounddevice-0.3.5-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): CFFI in /usr/lib/python3/dist-packages (from sounddevice)
Requirement already satisfied (use --upgrade to upgrade): pycparser in /usr/lib/python3/dist-packages (from CFFI->sounddevice)
Installing collected packages: sounddevice
Successfully installed sounddevice
Cleaning up...
$ python3 -m sounddevice
Traceback (most recent call last):
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/fiol/.local/lib/python3.4/site-packages/sounddevice.py", line 313, in <module>
""")
File "/usr/lib/python3/dist-packages/cffi/api.py", line 104, in cdef
self._parser.parse(csource, override=override, packed=packed)
File "/usr/lib/python3/dist-packages/cffi/cparser.py", line 157, in parse
self._internal_parse(csource)
File "/usr/lib/python3/dist-packages/cffi/cparser.py", line 169, in _internal_parse
'%s ..." for now (literally)' % key)
cffi.api.CDefError: only supports the syntax "#define paUInt8 ..." for now (literally)
Then I found that maybe I had an outdated CFFI installed (which comes with my rather old distribution) so I installed the libffi-dev package and...
$ python3 -m pip install cffi --user --upgrade
Downloading/unpacking cffi from https://pypi.python.org/packages/0a/f3/686af8873b70028fccf67b15c78fd4e4667a3da995007afc71e786d61b0a/cffi-1.8.3.tar.gz#md5=c8e877fe0426a99d0cf5872cf2f95b27
Downloading cffi-1.8.3.tar.gz (403kB): 403kB downloaded
Running setup.py (path:/tmp/pip_build_fiol/cffi/setup.py) egg_info for package cffi
Downloading/unpacking pycparser from https://pypi.python.org/packages/be/64/1bb257ffb17d01f4a38d7ce686809a736837ad4371bcc5c42ba7a715c3ac/pycparser-2.17.tar.gz#md5=ca98dcb50bc1276f230118f6af5a40c7 (from cffi)
Downloading pycparser-2.17.tar.gz (231kB): 231kB downloaded
Running setup.py (path:/tmp/pip_build_fiol/pycparser/setup.py) egg_info for package pycparser
warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
warning: no previously-included files matching 'lextab.*' found under directory 'tests'
warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
warning: no previously-included files matching 'lextab.*' found under directory 'examples'
Installing collected packages: cffi, pycparser
Running setup.py install for cffi
building '_cffi_backend' extension
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -DUSE__THREAD -I/usr/include/python3.4m -c c/_cffi_backend.c -o build/temp.linux-x86_64-3.4/c/_cffi_backend.o
x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-Bsymbolic-functions -Wl,-z,relro -g -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 build/temp.linux-x86_64-3.4/c/_cffi_backend.o -lffi -o build/lib.linux-x86_64-3.4/_cffi_backend.cpython-34m.so
Running setup.py install for pycparser
warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
warning: no previously-included files matching 'lextab.*' found under directory 'tests'
warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
warning: no previously-included files matching 'lextab.*' found under directory 'examples'
Build the lexing/parsing tables
Successfully installed cffi pycparser
Cleaning up...
$ python3 -m sounddevice
0 HDA Intel HDMI: 0 (hw:0,3), ALSA (0 in, 8 out)
1 HDA Intel HDMI: 1 (hw:0,7), ALSA (0 in, 8 out)
2 HDA Intel HDMI: 2 (hw:0,8), ALSA (0 in, 8 out)
3 HDA Intel PCH: ALC292 Analog (hw:1,0), ALSA (2 in, 2 out)
4 hdmi, ALSA (0 in, 8 out)
5 pulse, ALSA (32 in, 32 out)
* 6 default, ALSA (32 in, 32 out)
$
So... May I suggest that sounddevice (or its documentation) is updated to reflect the dependency on a specific version of CFFI?
Thanks!
First, set up a stereo signal. Here: white noise on the left channel, and a silent right channel.
import sounddevice
import numpy as np
noise = np.random.randn(44100)
silence = np.zeros_like(noise)
signal = np.array(zip(noise, silence))
It looks as expected:
>>> signal
array([[-1.31754488, 0. ],
[-0.87951546, 0. ],
[ 1.09275125, 0. ],
...,
[ 0.42013106, 0. ],
[ 1.25192917, 0. ],
[-1.08305476, 0. ]])
Now, play back this 2D array using sounddevice.play
.
sounddevice.play(signal)
I expect the right channel to be completely silent. However, it isn't! A quieter version of the noise on the left channel is being played back on the right channel. The left channel sounds as expected.
The same happens when I switch the channels, and with any dtype
(I tried int8
, float32
, float64
). Each channel bleeds into the other. It is most easily heard when wearing earphones.
I have of course verified that the balance of my system audio output is centered, and that other audio software (e.g., Audacity) behaves correctly. I have also rebooted. The culprit does seem to be python-sounddevice.
Can anyone confirm that I'm not the only one with this issue? I'm on a late 2013 rMBP 13", running OS X 10.11.3.
Is it possible, using this library's play() function, to play multiple sounds (wav files) at once?
This only happens if a script ends before playback is finished.
This isn't a real problem since you would use a blocking call or at least sd.wait()
in a Python script.
But crashing the interpreter isn't really nice ...
This is an example script to reproduce the error:
import sounddevice as sd
import numpy as np
sd.play(np.zeros(100000))
Note that the crash doesn't happen every time, only occasionally.
Hi,
when loading the sounddevice module after the visual or event module from psychopy I get an error message when finishing or quitting the script (sys.exit()
):
*** Error in `python': free(): invalid pointer: 0x00007fc9289b8540 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x6ef45)[0x7fc92868af45]
/lib/x86_64-linux-gnu/libc.so.6(+0x746b6)[0x7fc9286906b6]
/lib/x86_64-linux-gnu/libc.so.6(+0x74e9e)[0x7fc928690e9e]
/lib/x86_64-linux-gnu/libc.so.6(fclose+0x103)[0x7fc9286815f3]
/usr/lib/x86_64-linux-gnu/libopenal.so.1(+0xae13)[0x7fc909480e13]
/lib64/ld-linux-x86-64.so.2(+0xf9b7)[0x7fc9295109b7]
/lib/x86_64-linux-gnu/libc.so.6(+0x35b78)[0x7fc928651b78]
/lib/x86_64-linux-gnu/libc.so.6(+0x35bc5)[0x7fc928651bc5]
python[0x52540f]
python[0x52288d]
python(PyErr_PrintEx+0x36)[0x522176]
python[0x42ec24]
python(Py_Main+0x6c1)[0x49dc51]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fc92863c730]
python(_start+0x29)[0x49d4a9]
======= Memory map: ========
00400000-006eb000 r-xp 00000000 08:03 4982615 /usr/bin/python2.7
008eb000-008ed000 r--p 002eb000 08:03 4982615 /usr/bin/python2.7
008ed000-00964000 rw-p 002ed000 08:03 4982615 /usr/bin/python2.7
00964000-00987000 rw-p 00000000 00:00 0
022c3000-07fa3000 rw-p 00000000 00:00 0 [heap]
7fc8ec000000-7fc8ec021000 rw-p 00000000 00:00 0
...
minimal example causing the error:
from psychopy import event
import sounddevice
this is fine:
import sounddevice
from psychopy import event
The workaround for now is just to import sounddevice before the psychopy modules.
I'm running debian unstable with psychopy '1.83.04'
Do you have any clue, what could be the reason for this. Is it a sounddevice or psychopy issue? I've posted this to the psychopy forum as well, in case they have an idea about it.
best wishes
Piotr
I want to record 2 channels from a multi-channel soundcard. I thought that would be possible with the mapping parameter, but found out that the stream (e.g. RawInputStream) do not support this.
Is there another way to record selected channels with a stream?
I have python code that is running on raspberry pi B++ that uses the sounddevice library that lets you play and record sounds with python. I have successfully installed the modules. I can confirm through the python command line and enter import sounddevice as sd is works without errors. I have also confirmed by typing help ('modules')
in python command line and sounddevice module appears. Only when I am running this code in an independent python program does the ImportError: No module name sounddevice
appear.
Hope some one can help.
Here is the included code:
import sounddevice as sd
The error:
ImportError: No module name sounddevice
Hi,
I am writing an application that requires plugging and unplugging audio devices multiple times. Unfortunately, the query_devices() only displays the devices available at when the import sounddevice is performed.
Is there a way of updating the list without having to reload the module? I am using python 2.7 and I can see the behaviour is the same on OSX, Windows and Raspbian.
Thanks for your help
Adrien
Is it possible to easily tell when a sound mad using play()
ends, without using the blocking option, like a callback?
when I load a module, which contains commands to play sound, no sound is played (no error message). I have the same problem on linux as well as on windows 8
minimal example:
main.py
:
import module1
module1.py
:
import sounddevice as sd
import soundfile as sf
import time
data, fs = sf.read('startle50ms.wav')
sd.play(data,fs)
print 'sound played'
time.sleep(1)
If I run module1.py
, everything is ok. If I run main.py
, which is supposed to load module1, no sound is played; no error message displayed. Everything seems to be ok, but I can't hear any sound
If you are aware of a simple solution, it would be great, otherwise I would have to rewrite quite some code (to put everything in one script), if I wanted to use sounddevice in our experiment.
Not sure what happened but I see the following output after $pip install sounddevice --user
. Can't move forward at all, please help.
Mac OSX 10.10.5 (Yosemite)
python 2.7.7
Downloading/unpacking sounddevice
Downloading sounddevice-0.3.1.tar.gz
Running setup.py egg_info for package sounddevice
error: package directory '_sounddevice_data' does not exist
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/sounddevice.egg-info
writing requirements to pip-egg-info/sounddevice.egg-info/requires.txt
writing pip-egg-info/sounddevice.egg-info/PKG-INFO
writing top-level names to pip-egg-info/sounddevice.egg-info/top_level.txt
writing dependency_links to pip-egg-info/sounddevice.egg-info/dependency_links.txt
writing manifest file 'pip-egg-info/sounddevice.egg-info/SOURCES.txt'
warning: manifest_maker: standard file '-c' not found
error: package directory '_sounddevice_data' does not exist
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /var/folders/t6/c_sf37fx0yj_6glzll5ttp_r0000gn/T/pip-build/sounddevice
Storing complete log in /Users/dahoopster/Library/Logs/pip.log
Hello there,
i work on a MUSHRA like listening test for multispeakersetups at the moment and use sounddevice.play()
and stop()
to play multichannel audio files out of my GUI. I can switch between sounds and start them playing in a loop.
But what i am not able to do is to let the the loop start from a specific start point. What i would like to do is to switch between the sounds without restarting them. So get the actual time position of the track i just stopped and feed that information as the starting point for an other track so that i can compare the stimuli better.
Is there a possibility to do that or a known workaround to achieve this behaviour? Someone experience with that?
Thanks and regards,
Michael
Just wondering where these get installed to, and if there is an API to find the location ?
Hi,
I'm running play() without blocking, how can I tell when playback finishes?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.