【发布时间】:2019-08-21 22:56:58
【问题描述】:
我正在尝试对这样的 wav 文件进行语音识别:
var config = SpeechConfig.FromSubscription("mykey", "myregion");
using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromWavFileInput(@"/Full/Path/To/File.wav")))
{
recognizer.Recognized += (s, e) =>
{
if (e.Result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine(e.Result.Text);
}
};
await recognizer.StartContinuousRecognitionAsync();
}
但我收到此错误:
Unhandled Exception: System.AggregateException: One or more errors occurred. (Exception with an error code: 0xa (SPXERR_INVALID_HEADER)) ---> System.ApplicationException: Exception with an error code: 0xa (SPXERR_INVALID_HEADER)
at Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail(IntPtr hr)
at Microsoft.CognitiveServices.Speech.Recognizer.FromConfig(GetRecognizerFromConfigDelegate fromConfig, SpeechConfig speechConfig, AudioConfig audioConfig)
at Microsoft.CognitiveServices.Speech.SpeechRecognizer..ctor(SpeechConfig speechConfig, AudioConfig audioConfig)
at mynamespace.Program.RecognizeSpeechAsync() in Program.cs:line 14
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.Wait()
at mynamespace.Program.Main() in Program.cs:line 46
第 14 行是
using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromWavFileInput(@"/Full/Path/To/File.wav")))
行
我实际上打算如何对文件使用语音服务?我让它在现场麦克风输入上工作。
我刚刚再次尝试使用不同格式的文件(WAV 文件,16 kHz 采样率,单声道),现在出现此错误:
libc++abi.dylib: terminating with uncaught exception of type
Microsoft::CognitiveServices::Speech::Impl::ExceptionWithCallStack: Exception with
an error code: 0xd (SPXERR_ABORT)
【问题讨论】:
-
我下载了一个用于 Internet 的 wav 文件,并且能够使用它,但是每当我从我自己构建的 JS ui 构建 wav 时,我都会遇到和你一样的麻烦.
-
我找到了解决问题的方法。原来我必须在前端 javascript+html UI 中实际以 wav 格式录制。问题是我在音频/webm 中录制并将文件发布到我的后端。虽然我确实在后端成功地将它转换为 wav 并且它确实可以正常播放,但语音库并不喜欢这样。只有当我确定我的前端是 wav 时它才起作用。我希望这会有所帮助。
标签: c# azure speech-recognition microsoft-cognitive