An Azure service that integrates speech processing into apps and services.
@sam this is the method I am using to make the call. You should be able to print to file with the above suggestions and below snippet.
I would also request you to try the same for debugging with your actual speech resource key and region config if the container endpoint is failing to do so.
public static async Task RecognitionWithLanguageAndDetailedOutputAsync()
{
// Creates an instance of a speech config with specified subscription key and service region.
// Replace with your own subscription key and service region (e.g., "westus") if using the Azure service API
var config = SpeechConfig.FromSubscription("<your_key>", "<your_region>");
config.SpeechRecognitionLanguage = "hi-IN";
// Replace the language with your language in BCP-47 format, e.g., en-US.
//var language = "en-US";
config.OutputFormat = OutputFormat.Detailed;
FileStream filestream = new FileStream("out.txt", FileMode.Create);
var streamwriter = new StreamWriter(filestream);
streamwriter.AutoFlush = true;
Console.SetOut(streamwriter);
Console.SetError(streamwriter);
// Creates a speech recognizer for the specified language, using microphone as audio input.
// Requests detailed output format.
//using (var recognizer = new SpeechRecognizer(config, language))
using (var recognizer = new SpeechRecognizer(config))
{
// Starts recognizing.
//Console.WriteLine($"Say something in {language} ...");
Console.WriteLine($"Say something ...");
// Starts speech recognition, and returns after a single utterance is recognized. The end of a
// single utterance is determined by listening for silence at the end or until a maximum of 15
// seconds of audio is processed. The task returns the recognition text as result.
// Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
// shot recognition like command or query.
// For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);
// Checks result.
if (result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"RECOGNIZED: Text={result.Text}");
Console.WriteLine(" DETAILED RESULTS:");
var detailedResults = result.Best();
foreach (var item in detailedResults) // NOTE: We need to put this in all languages, or take it out of CSharp
{
Console.WriteLine($" Confidence: {item.Confidence}, Text: {item.Text}, LexicalForm: {item.LexicalForm}, NormalizedForm: {item.NormalizedForm}, MaskedNormalizedForm: {item.MaskedNormalizedForm}");
// Console.W($" Confidence: {item.Confidence}, Text: {item.Text}, LexicalForm: {item.LexicalForm}, NormalizedForm: {item.NormalizedForm}, MaskedNormalizedForm: {item.MaskedNormalizedForm}");
}
}
else if (result.Reason == ResultReason.NoMatch)
{
Console.WriteLine($"NOMATCH: Speech could not be recognized.");
}
else if (result.Reason == ResultReason.Canceled)
{
var cancellation = CancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
}
}
}