79512692

Date: 2025-03-16 14:21:36
Score: 0.5
Natty:
Report link

The answer/solution to this question is to use a WaveFileWriter and save the bytes directly to a MemoryStream rather a file. The WaveFileWritter wraps the raw bytes[] as a formatted Wave stream. Change rate and channels as needed.

writerMem = new WaveFileWriter(memStream, new WaveFormat(44100, 16, 1));

Write read bytes to the WaveFileWriter:

writerMem.Write(e.Buffer, 0, e.BytesRecorded);

Call the API passing the Memory Stream only

var recResult = speechToText.Recognize(
audio: memStream,
model: "pt-BR_Multimedia",
contentType: "audio/wav");

This way, the API accepts the MemoryStream and identify the WAVE stream from within.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Marcio Correa