【发布时间】:2012-01-24 21:16:18
【问题描述】:
我正在尝试将android语音识别服务收听的音频数据保存在一个文件中。
实际上我实现了RecognitionListener,如下所述:
Speech to Text on Android
将数据保存到缓冲区中,如下所示: Capturing audio sent to Google's speech recognition server
并将缓冲区写入 Wav 文件,如此处所示。 Android Record raw bytes into WAVE file for Http Streaming
我的问题是如何获得适当的音频设置以保存在 wav 文件的标题中。 其实我在播放wav文件的时候只听到奇怪的噪音,用这个参数,
short nChannels=2;// audio channels
int sRate=44100; // Sample rate
short bSamples = 16;// byteSample
或者什么都没有:
short nChannels=1;// audio channels
int sRate=8000; // Sample rate
short bSamples = 16;// byteSample
令人困惑的是,我首先从 logcat 中查看语音识别任务的参数 将 PLAYBACK 采样率设置为 44100 HZ:
12-20 14:41:34.007: DEBUG/AudioHardwareALSA(2364): Set PLAYBACK PCM format to S16_LE (Signed 16 bit Little Endian)
12-20 14:41:34.007: DEBUG/AudioHardwareALSA(2364): Using 2 channels for PLAYBACK.
12-20 14:41:34.007: DEBUG/AudioHardwareALSA(2364): Set PLAYBACK sample rate to 44100 HZ
12-20 14:41:34.007: DEBUG/AudioHardwareALSA(2364): Buffer size: 2048
12-20 14:41:34.007: DEBUG/AudioHardwareALSA(2364): Latency: 46439
然后 aInfo.SampleRate = 8000 当它播放要发送到谷歌服务器的文件时:
12-20 14:41:36.152: DEBUG/(2364): PV_Wav_Parser::InitWavParser
12-20 14:41:36.152: DEBUG/(2364): File open Succes
12-20 14:41:36.152: DEBUG/(2364): File SEEK End Succes
...
12-20 14:41:36.152: DEBUG/(2364): PV_Wav_Parser::ReadData
12-20 14:41:36.152: DEBUG/(2364): Data Read buff = RIFF?
12-20 14:41:36.152: DEBUG/(2364): Data Read = RIFF?
12-20 14:41:36.152: DEBUG/(2364): PV_Wav_Parser::ReadData
12-20 14:41:36.152: DEBUG/(2364): Data Read buff = fmt
...
12-20 14:41:36.152: DEBUG/(2364): PVWAVPARSER_OK
12-20 14:41:36.156: DEBUG/(2364): aInfo.AudioFormat = 1
12-20 14:41:36.156: DEBUG/(2364): aInfo.NumChannels = 1
12-20 14:41:36.156: DEBUG/(2364): aInfo.SampleRate = 8000
12-20 14:41:36.156: DEBUG/(2364): aInfo.ByteRate = 16000
12-20 14:41:36.156: DEBUG/(2364): aInfo.BlockAlign = 2
12-20 14:41:36.156: DEBUG/(2364): aInfo.BitsPerSample = 16
12-20 14:41:36.156: DEBUG/(2364): aInfo.BytesPerSample = 2
12-20 14:41:36.156: DEBUG/(2364): aInfo.NumSamples = 2258
那么,我怎样才能找到正确的参数来将音频缓冲区保存在一个好的 wav 音频文件中呢?
【问题讨论】:
-
您找到解决方案了吗?
-
似乎你在这方面已经走得最远了。 mmmx,你能解决这个问题吗?
标签: android audio speech-recognition wav voice-recognition