我正在尝试获取转录及其单词信息,专门用于计时。为了避免超过305秒的最大允许流持续时间,此错误我正在创建新的StreamingRecognizeRequest。在这种情况下,某些字节块会丢失。而且wordtimeoffset的主要功能也会在新请求时重置。这没有用。
static async Task<object> StreamAsync(Stream outputStream,SpeechClient speech)
{
try
{
var streamingCall = speech.StreamingRecognize();
if (firstMessage == true)
{
Console.WriteLine("new request created.");
// Write the initial request with the config.
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
StreamingConfig = new StreamingRecognitionConfig()
{
Config = new RecognitionConfig()
{
Encoding =
RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en-US",
// Model = "video",
EnableWordTimeOffsets = true,
EnableSpeakerDiarization = true,
DiarizationSpeakerCount = 2,
EnableAutomaticPunctuation = true,
},
InterimResults = true,
}
});
// Print responses as they arrive.
Task printResponses = Task.Run(async () =>
{
while (await streamingCall.ResponseStream.MoveNext(
default(CancellationToken)))
{
foreach (var result in streamingCall.ResponseStream
.Current.Results)
{
int tag = 1;
string speakertext = "";
string transcript = "";
string currenttext = "";
int currentspeaker = 0;
Google.Protobuf.WellKnownTypes.Duration starttime = null;
Google.Protobuf.WellKnownTypes.Duration endtime = null;
foreach (var wordinfo in result.Alternatives[0].Words)
{
speakertext = speakertext + " " + wordinfo.Word;
starttime = wordinfo.StartTime;
endtime = wordinfo.EndTime;
}
if (speakertext != "")
{
write_transcript(@"C:\Podia\20190322105215.txt", starttime + " --> " + endtime + " " + speakertext);
speakertext = "";
starttime = null;
endtime = null;
}
}
}
});
firstMessage = false;
}
if (firstMessage == false)
{
var buffer = new byte[32 * 1024];
// var buffer = new byte[1024];
int bytesRead;
int numberofwrites = 200;
while ((bytesRead = await outputStream.ReadAsync(
buffer, 0, buffer.Length)) > 0)
{
if (numberofwrites > 0)
{
await streamingCall.WriteAsync(
new StreamingRecognizeRequest()
{
AudioContent = Google.Protobuf.ByteString
.CopyFrom(buffer, 0, bytesRead),
});
numberofwrites--;
}
else
{
// numberofwrites = 10;
firstMessage = true;
StreamAsync(outputStream, speech).Wait();
}
};
}
return 0;
}
catch (Exception ex) {
Console.Write(ex.ToString());
// throw ex;
return 0;
}
}
我得到的wordtimeoffset结果不正确,这显然是不正确的。
“ 5.500s”->“ 5.700s”我要去玩《边境凯瑟琳》,因为她过去三个月来一直在现场,我一直很喜欢
“ 6.100s”->“ 6.400s”休伦市您对自我们开始以来发生的事情有何感想
“ 1.400s”->“ 1.500s”我关于性别工资的电话交谈 “ 5.300s”->“ 5.600s”我敢打赌,因为我一直对感兴趣的人数不满,所以这是黄金。
所以“我的电话交谈..”的行以1.400秒的新开始时间开始。应该持续6.400秒+秒。