gpt4 book ai didi

c++ - webRTC : How to apply webRTC's VAD on audio through samples obtained from WAV file

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:34:28 51 4
gpt4 key购买 nike

目前,我正在解析 wav 文件并在 std::vector<int16_t> sample 中存储样本 .现在,我想对这些数据应用 VAD(语音事件检测)以找出语音的“区域”,更具体地说是单词的开始和结束。

解析的 wav 文件是 16KHz,16 位 PCM,单声道。我的代码是用 C++ 编写的。

我已经搜索了很多,但找不到关于 webRTC 的 VAD 功能的适当文档。

根据我的发现,我需要使用的函数是 WebRtcVad_Process() .它的原型(prototype)如下:

int WebRtcVad_Process(VadInst* handle, int fs, const int16_t* audio_frame,
size_t frame_length)

根据我在这里找到的内容:https://stackoverflow.com/a/36826564/6487831

Each frame of audio that you send to the VAD must be 10, 20 or 30 milliseconds long. Here's an outline of an example that assumes audio_frame is 10 ms (320 bytes) of audio at 16000 Hz:

int is_voiced = WebRtcVad_Process(vad, 16000, audio_frame, 160);

有道理:

1 sample = 2B = 16 bits  
SampleRate = 16000 sample/sec = 16 samples/ms
For 10 ms, no of samples = 160

因此,基于此,我实现了这个:

const int16_t * temp = sample.data();
for(int i = 0, ms = 0; i < sample.size(); i += 160, ms++)
{
int isActive = WebRtcVad_Process(vad, 16000, temp, 160); //10 ms window
std::cout<<ms<<" ms : "<<isActive<<std::endl;
temp = temp + 160; // processed 160 samples
}

现在,我不确定这是否正确。另外,我也不确定这是否会给我正确的输出。

所以,

  • 是否可以使用直接从 wav 文件解析的样本,还是需要一些处理?
  • 我是否在寻找正确的功能来完成这项工作?
  • 如何使用函数对音频流进行正确的VAD?
  • 是否可以区分口语词?
  • 检查我得到的输出是否正确的最佳方法是什么?
  • 如果不是,完成这项任务的最佳方法是什么?

最佳答案

首先我要说的是,不,我认为您无法使用 VAD 将话语分割成单个单词。来自article on speech segmentation in Wikipedia :

One might expect that the inter-word spaces used by many written languages like English or Spanish would correspond to pauses in their spoken version, but that is true only in very slow speech, when the speaker deliberately inserts those pauses. In normal speech, one typically finds many consecutive words being said with no pauses between them, and often the final sounds of one word blend smoothly or fuse with the initial sounds of the next word.

也就是说,我会尽量回答您的其他问题。

  1. 在运行 VAD 之前,您需要将可以压缩的 WAV 文件解码为原始 PCM 音频数据。参见例如Reading and processing WAV file data in C/C++ .或者,您可以在运行代码之前使用 sox 之类的工具将 WAV 文件转换为原始音频。此命令会将任何格式的 WAV 文件转换为 WebRTCVAD 期望的格式的 16 KHz、16 位 PCM:

    sox my_file.wav -r 16000 -b 16 -c 1 -e signed-integer -B my_file.raw
  2. 看起来您正在使用正确的功能。更具体地说,您应该这样做:

    #include "webrtc/common_audio/vad/include/webrtc_vad.h"
    // ...
    VadInst *vad;
    WebRtcVad_Create(&vad);
    WebRtcVad_Init(vad);
    const int16_t * temp = sample.data();
    for(int i = 0, ms = 0; i < sample.size(); i += 160, ms += 10)
    {
    int isActive = WebRtcVad_Process(vad, 16000, temp, 160); //10 ms window
    std::cout << ms << " ms : " << isActive << std::endl;
    temp = temp + 160; // processed 160 samples (320 bytes)
    }
  3. 要查看它是否正常工作,您可以运行已知文件并查看是否获得预期的结果。例如,您可以从处理静音开始,并确认您永远不会(或很少——此算法并不完美)看到从 WebRtcVad_Process 返回的有声结果。然后你可以尝试一个文件,除了中间的一个简短的话语等之外,所有的文件都是静音的。如果你想与现有的测试进行比较,py-webrtcvad 模块有一个单元测试可以做到这一点;查看test_process_file function .

  4. 要进行词级分割,您可能需要找到一个语音识别库来执行此操作,或者让您可以访问执行此操作所需的信息。例如。 this thread on the Kaldi mailing list好像在讲怎么分词。

关于c++ - webRTC : How to apply webRTC's VAD on audio through samples obtained from WAV file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44457162/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com