流输入以进行语音识别

时间:2020-02-17 18:07:29

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

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

我尝试将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)

1 个答案:

答案 0 :(得分:0)

您可以使用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)