【问题标题】:Streaming input for speech recognition用于语音识别的流式输入
【发布时间】:2024-05-01 23:05:03
【问题描述】:

如何从声音流中提取特征?

我尝试将 htkpytorch 或其他库用于 filterbank。 但他们需要加载 wav 文件。

我想直接处理pyaudio的麦克风输入。

p = pyaudio.PyAudio()
stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True)
while stream.is_active(): 
    input = stream.read(CHUNK)

【问题讨论】:

    标签: python speech-recognition audio-streaming speech-to-text pyaudio


    【解决方案1】:

    您可以使用 librosa,非常标准的库。您需要流功能:

    https://librosa.github.io/librosa/generated/librosa.core.stream.html

    p = pyaudio.PyAudio()
    stream = p.open(format=pyaudio.paInt16, channels=1, rate=44100, input=True)
    stream = librosa.stream(stream,
                             block_length=256,
                             frame_length=2048,
                             hop_length=2048)
    for y_block in stream:
         m_block = librosa.feature.melspectrogram(y_block, sr=sr,
                                                  n_fft=2048,
                                                  hop_length=2048,
                                                  center=False)
    

    【讨论】: