Comments (16)
You should check for buffer under-/overflows by running sd.get_status() right after sd.playrec()
.
If there are under-/overflows, you should try a larger block size with blocksize=1024
or blocksize=2048
.
If not, I don't really know ...
Your waveform indeed looks quite nasty.
from python-sounddevice.
How do I get the information out of sd.get_status()
? My python skills aren't that great :(
from python-sounddevice.
Have a look at the play_file.py example.
You can just print the returned status
variable.
from python-sounddevice.
Printing the status variable gets me nothing, seems like it's empty. It says that the status variable is of type <class 'sounddevice.CallbackFlags'>
which I'm not sure of what is, can it simply be printed?
from python-sounddevice.
Yes, it can simply be printed.
If there are no errors, it will just print an empty string.
If you want to avoid printing empty strings, you can use it like in the aforementioned example.
Here's the docs: http://python-sounddevice.readthedocs.io/#sounddevice.CallbackFlags
You can also look at the source code, the relevant part is the __str__()
method, which automatically gets called by print()
.
If you don't get any over-/underflow errors, I don't really know what's going wrong.
Can you please still try it with different block sizes?
Do you also hear the strange noise while playrec()
is running or is it only in the recording?
Does the same strange noise appear if you only use play()
or only use rec()
?
from python-sounddevice.
Same thing happens with the sd.play()
. Simply recording from a different frequency generator gives a fine result so it definitely has to do with playback.
Block size of 1024 or 2048 made no difference. Neither does changing sample rate, all sample rates give the same crackling although higher sample rates reduces the time between cracks. One exception being using a Fs
of 44100 which results in pure static.
Since everything was fine with my previous USB sound card, could this be a driver issue?
from python-sounddevice.
Alright, I did something here. I used scipy.io.wavfile.read
to get a song stored as wav and played it with sd.play()
and it sounds perfect. How does sd.play()
interpret the array I create with scipy.io.wavfile.read()
and the array I create with np.sin()
differently? Why does it decide to go ham on the np.sin()
array? It has to do with the bitrate, right? The song being 16-bit while the np.sin()
is 64-bit? I guess I should try to play a high bitrate song with aplay(), if that doesn't work this probably has nothing to do with sounddevice
.
from python-sounddevice.
It seems to be with the data types. The wave file is dtype=int16
while the sine wave I'm playing is a np.float64
. My thinking was to simply create an int instead of a float by:
x=np.linspace(0.0, t, Fs*t)
y=32000*np.sin(1000*2.0*np.pi*x)
y=y.astype(np.int16)
But that gave me this result when using sd.play() or sd.playrec():
http://i64.tinypic.com/2ensx8y.jpg
Why this happens is beyond me. Increasing the block size will increase the on/off time that can been seen in the image. I'm having a hard time understanding how sounddevice
can differentiate between two int16
arrays as the wav file plays just fine.
from python-sounddevice.
I have no idea. This is really strange.
When I try your code, it works fine. I hear a single uninterrupted tone for 10 seconds.
Can you please try to save your generated signal (y
) to a WAV file and then read it back in and play it?
I guess the generated signal looks fine when you plot it, right?
Did you try using your sound card with other software that uses PortAudio (e.g. Audacity)?
BTW, you can simply drag images into the comments here (while editing), then they will be directly visible without having to click on a link.
from python-sounddevice.
I generated it as a wav file, transferred it to my computer and it plays just fine, plotting the waveform shows that the array itself is without any issues. This has to do with sd.play() which for some reason is struggeling to handle the data even after it has been converted to a wav file and back into a int16 array :(
from python-sounddevice.
The sounddevice
module theoretically supports float64
, float32
, int32
, int16
, int8
and uint8
. And it shouldn't matter if you create the signal with NumPy or if you load it from a file.
You could try using the newest release of PortAudio (19.6.0). I guess there is no Raspbian package yet, so you'll have to compile it manually.
from python-sounddevice.
The issue was with the dimension of the array. Giving the sd.play() a two dimensional array for both left and right channel made it work :) Don't ask me why :(
from python-sounddevice.
Great that you found a way that works!
It would still be interesting to find out if I can do something to avoid such errors in the future.
What was the dimension of the array when it worked and when it didn't work?
What were their shapes?
from python-sounddevice.
print y.dtype, y.shape, y.ndim, y.size, type(y)
int16 (48000, 2) 2 96000 <type 'numpy.ndarray'>
While the one that gave the result in the image above:
int16 (48000,) 1 48000 <type 'numpy.ndarray'>
Using int32 does not seem to work though, it just outputs nothing and records loud static regardless.
I also have a different problem that's not directly related to the topic of this thread though. I have a function that calculated the THD+N of a signal. Sending the y-array directly to this function returns a THD+N of something like 0.0003%, but sending the signal after it has been played and recorded gives a THD+N of 0.14% or there abouts. Calculating the THD+N of sine waves generated by my phone returns about 0.02% which is reasonable from a phone I guess. This USB sound card is supposed to ble able to output 0.0006 % THD+N at 1khz, so why does it output 0.14%? :\
I really appreciete the replies by the way :)
from python-sounddevice.
Just to make sure that I understand this correctly:
This only happens with one specific USB sound card, right?
If you use a different sound card, it doesn't happen?
This very much looks like a problem of PortAudio and the driver of the USB sound card.
Did you try Audacity?
Or any other app from http://portaudio.com/apps.html?
from python-sounddevice.
@Plecto123 Any news on this?
from python-sounddevice.
Related Issues (20)
- 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
- OSERROR portaudio library not found
- Advice on detecting when Sounddevice has stopped playing audio (and using multiple OutputStreams)
- Inconsistent order of channels HOT 2
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.