我们正在使用Microsoft认知服务进行语音转文本的实验。我们的要求之一是拥有字级时间戳。这对于短的wav文件(例如2-3分钟的音频)可以正常工作,但是对于较大的文件,我们会出现错误:“在反序列化类型Microsoft.CognitiveServices.Speech.DetailedSpeechRecognitionResultCollection的对象时发生错误。无法将值'2152200000'解析为类型'Int32'。”
关于我如何解决这个问题的任何暗示将不胜感激。预先感谢!
代码段:
config.OutputFormat = OutputFormat.Detailed;
config.RequestWordLevelTimestamps();
using (var audioInput = AudioConfig.FromWavFileInput(wavfile))
{
using var recognizer = new SpeechRecognizer(config, audioInput);
recognizer.Recognized += (s, e) =>
{
if (e.Result.Reason == ResultReason.RecognizedSpeech)
{
var framesStart = TimeSpan.FromTicks(e.Result.OffsetInTicks).TotalMilliseconds / 40;
var te = new TranscriptElement((long)framesStart, e.Result.Text, languageCode);
// Eventually fails on the following line:
var words = e.Result.Best().OrderByDescending(x => x.Confidence).First().Words;
foreach (var w in words.OrderBy(w => w.Offset))
{
var start = TimeSpan.FromTicks(w.Offset).TotalMilliseconds / 40;
var duration = TimeSpan.FromTicks(w.Duration).TotalMilliseconds / 40;
te.SingleWords.Add(new TranscriptSingleWord((long)start, (long)(start + duration), w.Word));
}
transcriptElements.Add(te);
}
else if (e.Result.Reason == ResultReason.NoMatch)
{
_logger.LogError($"NOMATCH: Speech could not be recognized.");
}
};
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
Task.WaitAny(new[] { stopRecognition.Task });
await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
}
这是扩展名用于偏移量的数据类型中的错误。一个int只能跟踪约214s的音频。
您可以通过SpeechServiceResponse_JsonResult
属性从结果的属性集合中访问Best()方法正在使用的原始JSON,直到有可用的修复程序为止。