gpt4 book ai didi

c# - 如何从文件中进行语音识别,System.ApplicationException 0xa SPXERR_INVALID_HEADER

转载 作者:行者123 更新时间:2023-12-03 00:26:28 24 4
gpt4 key购买 nike

我正在尝试对这样的 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)

最佳答案

正如您所说 - 它似乎正在使用标准 WAV 文件......

I downloaded a wav file for the Internet and I was able to make it work with

您自制的 WAV 文件似乎不符合预期的 WAV 格式规范(WAV/PCM 16 位、16 kHz/8 kHz、单声道音频)?

沃尔夫冈

关于c# - 如何从文件中进行语音识别,System.ApplicationException 0xa SPXERR_INVALID_HEADER,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56647060/

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