Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loopback record audio from speaker return zero array #168

Open
sparkstrike opened this issue Feb 28, 2023 · 5 comments
Open

loopback record audio from speaker return zero array #168

sparkstrike opened this issue Feb 28, 2023 · 5 comments

Comments

@sparkstrike
Copy link

sparkstrike commented Feb 28, 2023

First of all, thanks so much for your work on it!
I tried to record audio from speaker, it return a array with correct shape, but all element is zero: [[0, 0], [0, 0], ...], and the data return immediately (not 5 second) . It is strange that it works well yesterday and record by pc's physical microphone (not loopback).

environment
PC: DELL G3 notebook computer; OS: win11; python3.7 and SoundCard v0.4.2

import soundcard as sc

OUTPUT_FILE_NAME = "out.wav"  # file name.
SAMPLE_RATE = 16000  # [Hz]. sampling rate.
RECORD_SEC = 5 #  [sec]. duration recording audio.

speaker = sc.default_speaker()  # it is my speaker
print(speaker)  # <Speaker 扬声器 (Realtek(R) Audio) (2 channels)>

micer = sc.get_microphone(id=str(speaker.name), include_loopback=True)  # loopback record

with micer.recorder(samplerate=SAMPLE_RATE) as mic:
    data = mic.record(numframes=SAMPLE_RATE * RECORD_SEC)
    print(data)  # data is a zero array, but data.shape is correct ???????


""" output
<Speaker 扬声器 (Realtek(R) Audio) (2 channels)>
[[0. 0.]
 [0. 0.]
 [0. 0.]
 ...
 [0. 0.]
 [0. 0.]
 [0. 0.]]
"""

The other strangenesss is that it return valid audio array when play a music, but return [0] array when a few seconds after the music stops playing. The gif show it. (The RECORD_SEC change to 2 second)

1

@bastibe
Copy link
Owner

bastibe commented Mar 2, 2023

Could you explain in a bit more detail in which case it returns zeros of the right shape immediately? This is not supposed to happen.

@wolfiex
Copy link

wolfiex commented Apr 27, 2023

I seem to have the same problem when using the microphone to record on Mac.

default_mic = sc.default_microphone()
samplerate = 48000
seconds = 20 
data = default_mic.record(samplerate=samplerate, numframes=samplerate*20)
print(data,len(data),max(data))
[<Microphone MacBook Pro Microphone (1 channels)>, <Microphone Microsoft Teams Audio (2 channels)>, <Microphone WebexMediaAudioDevice (2 channels)>]
0: MacBook Pro Microphone
1: Microsoft Teams Audio
2: WebexMediaAudioDevice
[[-0.]
 [-0.]
 [-0.]
 ...
 [-0.]
 [-0.]
 [-0.]] 960000 [-0.]

@bastibe
Copy link
Owner

bastibe commented Apr 28, 2023

@wolfiex this does not seem related to loopback recording, so this is a different problem. Please open a new issue.

@tez3998
Copy link

tez3998 commented Nov 29, 2023

@bastibe
This issue may be the same as #166 , because I saw same output when I opened that issue.
Using the latest master branch may resolve this issue.

@tez3998
Copy link

tez3998 commented Nov 29, 2023

@sparkstrike
Could you try using the latest version of master branch instead of the released version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants