我正在使用此代码通过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文件提交给认知服务部门进行转录。我是天蓝色的初学者,想按顺序执行此操作,因此也可以随时告诉我我的代码效率低下或错误。
答案 0 :(得分:1)
是的,要获取置信度分数,您需要配置SpeechConfig,如下所示以获取详细的输出格式。 config.OutputFormat = OutputFormat.Detailed; 使用Result.Best()方法将通过详细输出返回最佳识别。详细的输出将显示置信度得分。
请参考以下Speech recognition samples可以为您提供帮助的信息。希望对您有所帮助!