Skip to content

loopback record audio from speaker return zero array #168

@sparkstrike

Description

@sparkstrike

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions