相关文章推荐
善良的鞭炮  ·  springboot ...·  2 年前    · 
很拉风的烈酒  ·  git rev-parse ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

how to speech recognise from a file, System.ApplicationException 0xa SPXERR_INVALID_HEADER

Ask Question

I am trying to speech recognise on a wav file like this:

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();

But I am getting this error:

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

line 14 is the

using (var recognizer = new SpeechRecognizer(config, AudioConfig.FromWavFileInput(@"/Full/Path/To/File.wav")))

How am I actually meant to use the speech service on a file? I got it working on live mic input.

I just tried again with a file formatted differently (WAV file, 16 kHz sampling rate, mono) and I now get this error:

libc++abi.dylib: terminating with uncaught exception of type
Microsoft::CognitiveServices::Speech::Impl::ExceptionWithCallStack: Exception with
an error code: 0xd (SPXERR_ABORT)
                I downloaded a wav file for the Internet and I was able to make it work with that, but I bump into the same trouble as you whenever I build the wav myself from a JS ui I've built.
– Hugo Nava Kopp
                Jul 30, 2019 at 13:54
                I found the solution to my problem. It turned out I had to actually record in wav format in the frontend javascript+html UI. The problem was that I was recording in audio/webm and posting the file to my backend. Although I did convert it successfully to wav in the backend and it did play properly, the Speech library didn't like that. Only when I made sure my frontend was wav did it work. I hope this helps.
– Hugo Nava Kopp
                Sep 11, 2019 at 15:15

It looks like your home-created WAV file isn't following the expected WAV format specification (WAV/PCM 16-bit, 16 kHz/8 kHz, single-channel audio)?

Wolfgang

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.