用于语音识别的流式输入

2024-05-15 23:52:21 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从声音流中提取特征

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

Tags: 文件format声音inputstreampytorch特征open
1条回答
网友
1楼 · 发布于 2024-05-15 23:52:21

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

相关问题 更多 >