我可以从 Azure 认知服务检索转录的置信度吗?
Can I retrieve the confidence of the transcription from Azure Cognitive Services?
我正在使用此代码通过 Azure 认知服务转录 wav 文件。全部转录完成后,我可以获得置信度分数吗?
private static async Task<string> TranscribeWav(SpeechConfig config, string fileName)
{
var taskCompleteionSource = new TaskCompletionSource<int>();
var transcriptionStringBuilder = new StringBuilder();
using (var audioInput = AudioConfig.FromWavFileInput(fileName))
{
using (var recognizer = new SpeechRecognizer(config, audioInput))
{
// Subscribes to events.
recognizer.Recognizing += (sender, eventargs) =>
{
//TODO: Handle recognized intermediate result
//Console.WriteLine(eventargs.Result.Text);
};
recognizer.Recognized += (sender, eventargs) =>
{
if (eventargs.Result.Reason == ResultReason.RecognizedSpeech)
{
transcriptionStringBuilder.Append(eventargs.Result.Text);
}
else if (eventargs.Result.Reason == ResultReason.NoMatch)
{
//TODO: Handle not recognized value
}
};
recognizer.Canceled += (sender, eventargs) =>
{
if (eventargs.Reason == CancellationReason.Error)
{
//TODO: Handle error
}
if (eventargs.Reason == CancellationReason.EndOfStream)
{
Console.WriteLine($"End of stream ({transcriptionStringBuilder.ToString()})...");
}
taskCompleteionSource.TrySetResult(0);
};
recognizer.SessionStarted += (sender, eventargs) =>
{
//Started recognition session
};
recognizer.SessionStopped += (sender, eventargs) =>
{
//Ended recognition session
taskCompleteionSource.TrySetResult(0);
};
// Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
// Waits for completion.
// Use Task.WaitAny to keep the task rooted.
Task.WaitAny(new[] { taskCompleteionSource.Task });
// Stops recognition.
await recognizer.StopContinuousRecognitionAsync();
}
}
return transcriptionStringBuilder.ToString();
}
我的目的是将 wav 文件提交给认知服务进行转录。我是 azure 的新手,想按顺序执行此操作,所以也请随时告诉我我的代码效率低下或错误。
是的,为了获得置信度分数,您需要配置 SpeechConfig,如下所示以获得详细的输出格式。
config.OutputFormat = OutputFormat.Detailed;
使用 Result.Best() 方法,该方法将 return 具有详细输出的最佳识别。详细输出显示置信度分数。
请参考以下Speech recognition samples对您有帮助you.I希望对您有所帮助!
我正在使用此代码通过 Azure 认知服务转录 wav 文件。全部转录完成后,我可以获得置信度分数吗?
private static async Task<string> TranscribeWav(SpeechConfig config, string fileName)
{
var taskCompleteionSource = new TaskCompletionSource<int>();
var transcriptionStringBuilder = new StringBuilder();
using (var audioInput = AudioConfig.FromWavFileInput(fileName))
{
using (var recognizer = new SpeechRecognizer(config, audioInput))
{
// Subscribes to events.
recognizer.Recognizing += (sender, eventargs) =>
{
//TODO: Handle recognized intermediate result
//Console.WriteLine(eventargs.Result.Text);
};
recognizer.Recognized += (sender, eventargs) =>
{
if (eventargs.Result.Reason == ResultReason.RecognizedSpeech)
{
transcriptionStringBuilder.Append(eventargs.Result.Text);
}
else if (eventargs.Result.Reason == ResultReason.NoMatch)
{
//TODO: Handle not recognized value
}
};
recognizer.Canceled += (sender, eventargs) =>
{
if (eventargs.Reason == CancellationReason.Error)
{
//TODO: Handle error
}
if (eventargs.Reason == CancellationReason.EndOfStream)
{
Console.WriteLine($"End of stream ({transcriptionStringBuilder.ToString()})...");
}
taskCompleteionSource.TrySetResult(0);
};
recognizer.SessionStarted += (sender, eventargs) =>
{
//Started recognition session
};
recognizer.SessionStopped += (sender, eventargs) =>
{
//Ended recognition session
taskCompleteionSource.TrySetResult(0);
};
// Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
// Waits for completion.
// Use Task.WaitAny to keep the task rooted.
Task.WaitAny(new[] { taskCompleteionSource.Task });
// Stops recognition.
await recognizer.StopContinuousRecognitionAsync();
}
}
return transcriptionStringBuilder.ToString();
}
我的目的是将 wav 文件提交给认知服务进行转录。我是 azure 的新手,想按顺序执行此操作,所以也请随时告诉我我的代码效率低下或错误。
是的,为了获得置信度分数,您需要配置 SpeechConfig,如下所示以获得详细的输出格式。 config.OutputFormat = OutputFormat.Detailed; 使用 Result.Best() 方法,该方法将 return 具有详细输出的最佳识别。详细输出显示置信度分数。
请参考以下Speech recognition samples对您有帮助you.I希望对您有所帮助!