Comments (12)
Hmmm, I don't know what's going on there ...
Can you please print the return value of sd.wait()
?
Can you please try some values for blocksize
and see how that relates to the number of zeros you get?
from python-sounddevice.
I modified the snippet slightly it is now:
import sounddevice as sd
from scipy.io import wavfile
import numpy as np
from pprint import pprint
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',
blocksize: 'Block size (0 is optimal but may vary)' = 0,
loops: 'Number of recordings in loop' = 1,
format: 'dtype of recording' = 'float32'):
dev = sd.query_devices(sound_device)
pprint(dev)
sd.default.device = sound_device
sd.default.dtype = format
sd.default.blocksize = blocksize
print('Starting Recording')
channel_map = [int(c) for c in channel_map]
for i in range(loops):
print('Loop #', i)
rec = sd.rec(int(duration * dev['default_samplerate']), samplerate=int(dev['default_samplerate']), mapping=channel_map)
print(' sd.wait() ->', sd.wait())
for channel in range(rec.shape[1]):
non_silence = np.where(rec[:,channel] > float(0))[0]
print(' Ch. {}, initial silence {} samples'.format(channel, non_silence[0]))
wavfile.write(str(i) + out_file, int(dev['default_samplerate']), rec)
I tried to use a WASAPI device and recorded audio ten times in a loop.
It gave the following result (I also included the return of sd.wait()
, but it is always None
)
#: python audiorec.py -s "In 1 WASAPI" -b 1024 -l 10
{'default_high_input_latency': 0.01,
'default_high_output_latency': 0.0,
'default_low_input_latency': 0.003,
'default_low_output_latency': 0.0,
'default_samplerate': 48000.0,
'hostapi': 3,
'max_input_channels': 2,
'max_output_channels': 0,
'name': 'USBPAL In1 L/R (Terratec DMX 6fire WDM Audio)'}
Starting Recording
Loop # 0
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 1
sd.wait() -> None
Ch. 0, initial silence 447 samples
Ch. 1, initial silence 477 samples
Loop # 2
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 3
sd.wait() -> None
Ch. 0, initial silence 0 samples
Ch. 1, initial silence 1 samples
Loop # 4
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 5
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 6
sd.wait() -> None
Ch. 0, initial silence 265 samples
Ch. 1, initial silence 256 samples
Loop # 7
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 8
sd.wait() -> None
Ch. 0, initial silence 256 samples
Ch. 1, initial silence 256 samples
Loop # 9
sd.wait() -> None
Ch. 0, initial silence 257 samples
Ch. 1, initial silence 268 samples
Changing the blocksize did not see to affect the Asio device; unless I set the blocksize to the same as the samples displayed under "Asio latency" in the driver software, which yields about half the initial silence as any other value.
from python-sounddevice.
I think your code np.where(rec[:,channel] > float(0))[0][0]
doesn't yield the number of zeros but rather the number of non-positive values before the first positive value. Shouldn't it be rather something like rec[:, channel].nonzero()[0][0]
?
I also included the return of
sd.wait()
, but it is alwaysNone
OK, that's good, that means that there are no over/underflows.
You should probably only print this when its not None
.
from python-sounddevice.
I'm getting the same results, moreover I can confirm the silence when importing the out file in audacity and manually finding the first non zero sample.
However when I record om a MME device I am not getting any initial silence. Could it be an issue with PortAudio?
from python-sounddevice.
OK, if it doesn't happen in MME, it sure looks like a PortAudio issue.
from python-sounddevice.
You should probably ask there: http://www.portaudio.com/contacts.html
from python-sounddevice.
@mathiassmichno - You could try libportaudio64bit.dll from the portaudio-19.6.0-win branch at https://github.com/spatialaudio/portaudio-binaries
portaudio has fixed a lot of bugs since revision 1899 bundled in the sounddevice 0.3.5 Windows wheel.
from python-sounddevice.
Another option is to install the wheel with the updated PortAudio library from http://www.lfd.uci.edu/~gohlke/pythonlibs/#sounddevice
from python-sounddevice.
I downloaded the wheel from http://www.lfd.uci.edu/~gohlke/pythonlibs/#sounddevice
And it fixed the problem, at least according to my small test script.
Thanks @hiccup7!
from python-sounddevice.
I've just made a new release.
Can you please check if the problem is fixed now?
from python-sounddevice.
According to my small test, the problem is fixed, and the initial silence is gone.
from python-sounddevice.
OK, thanks!
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.