【问题标题】:Voice Activity Detection语音活动检测
【发布时间】:2020-05-13 14:33:32
【问题描述】:
【问题讨论】:
标签:
python-3.x
numpy
audio
speech-recognition
librosa
【解决方案1】:
py-webrtcvad,期望音频数据为 16 位 PCM little-endian - 这是 WAV 文件中最常见的存储格式。
librosa 及其底层 I/O 库 pysoundfile 但是始终返回范围 [-1.0, 1.0] 内的浮点数组。要将其转换为包含 16 位 PCM 的字节,您可以使用以下 float_to_pcm16 函数。
并且我已经测试使用read_pcm16 函数直接替换官方py-webrtcvad example 中的read_wave。但允许打开声音文件(WAV、FLAC、OGG)等支持的任何音频文件。
def float_to_pcm16(audio):
import numpy
ints = (audio * 32767).astype(numpy.int16)
little_endian = ints.astype('<u2')
buf = little_endian.tostring()
return buf
def read_pcm16(path):
import soundfile
audio, sample_rate = soundfile.read(path)
assert sample_rate in (8000, 16000, 32000, 48000)
pcm_data = float_to_pcm16(audio)
return pcm_data, sample_rate