bastibe / SoundCard

A Pure-Python Real-Time Audio Library
https://soundcard.readthedocs.io
BSD 3-Clause "New" or "Revised" License
689 stars 70 forks source link

Freezing code when no sound on a loopback device #70

Closed kehboard closed 4 years ago

kehboard commented 4 years ago

`import soundcard CHANNELS = 1 RATE = 44100 CHUNK =100

device = soundcard.all_microphones(include_loopback=True)[0] while True: data = device.record(CHUNK, samplerate=RATE, channels=CHANNELS) print(data) ` When i have sound on device this code is running ok. When i havent sound on device code freezes.

P.S. Sorry for my English

bastibe commented 4 years ago

What operating system are your running?

kehboard commented 4 years ago

Windows 10 x64, python 3.7

bastibe commented 4 years ago

Do you get an error message? What kind of sound card are you using? I'll try to replicate your error tonight.

kehboard commented 4 years ago

My audiocard is Realtek High Definition Audio (built-in soundcard in my laptop). I have not any error messages. I except when no sound on input record method returned array with zeros

bastibe commented 4 years ago

The latest commit should fix your issue. Apparently loopback devices do not return any audio data when there is no playback stream active.

Could you check that the fix works on your machine?

kehboard commented 4 years ago

It works on my machine