如何解决Azure Speech to Text 在 3-4 分钟后停止工作
我正在尝试转录大约 10-20 分钟的音频文件。 Azure Speech to Text 在大约 3 分 20 秒后停止。我正在使用连续识别,但我不确定问题是什么。这篇文章中的解决方案现已失效链接:
Azure Speech to Text stops working after 3 to 4 minutes in Android SDK Version 1.2.2
我的代码是:
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Linq;
namespace STTwithTime
{
class Program
{
static void Main(string[] args)
{
var key = "subscriptionkey";
var region = "region";
var audioFilePath = @"";
var speechConfig = SpeechConfig.FromSubscription(key,region);
// Generates timestamps
speechConfig.RequestWordLevelTimestamps();
speechConfig.OutputFormat = OutputFormat.Detailed;
var stopRecognition = new taskcompletionsource<int>();
var audioConfig = AudioConfig.FromWavFileInput(audioFilePath);
var recognizer = new SpeechRecognizer(speechConfig,audioConfig);
//display Recognized
recognizer.Recognized += (s,e) =>
{
if (e.Result.Reason == ResultReason.RecognizedSpeech)
{
var result = JsonConvert.DeserializeObject<Result>(e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult));
var maxConfidenceValue = result.NBest.Max(item => item.Confidence);
var maxConfidence = result.NBest.Find(item => item.Confidence == maxConfidenceValue);
Console.WriteLine("================================");
Console.WriteLine("Confidence:"+maxConfidence.Confidence);
Console.WriteLine("RECOGNIZED :" + maxConfidence.display);
Console.WriteLine("Duration: :" + Convert.Todouble(result.Duration) / 10000000);
Console.WriteLine("Words:");
foreach (var word in maxConfidence.Words) {
Console.WriteLine(word.word + "=> offset:" + Convert.Todouble(word.Offset) / 10000000 + " duration:" + Convert.Todouble(word.Duration) / 10000000);
}
}
else if (e.Result.Reason == ResultReason.NoMatch)
{
Console.WriteLine($"NOMATCH: Speech Could not be recognized.");
}
};
recognizer.Canceled += (s,e) =>
{
Console.WriteLine($"CANCELED: Reason={e.Reason}");
if (e.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
stopRecognition.TrySetResult(0);
};
recognizer.SessionStopped += (s,e) =>
{
Console.WriteLine("\n Session stopped event.");
stopRecognition.TrySetResult(0);
};
recognizer.StartContinuousRecognitionAsync().GetAwaiter().GetResult();
// Waits for completion. Use Task.WaitAny to keep the task rooted.
Task.WaitAny(new[] { stopRecognition.Task });
// Keeps external console from closing too quickly
string v = Console.ReadLine();
}
}
public class Word
{
public int Duration { get; set; }
public int Offset { get; set; }
public string word { get; set; }
}
public class NBest
{
public double Confidence { get; set; }
public string display { get; set; }
public string ITN { get; set; }
public string Lexical { get; set; }
public string MaskedITN { get; set; }
public List<Word> Words { get; set; }
}
public class Result
{
public string displayText { get; set; }
public int Duration { get; set; }
public string Id { get; set; }
public List<NBest> NBest { get; set; }
public int Offset { get; set; }
public string RecognitionStatus { get; set; }
}
}
我该如何解决这个问题?我需要转录整个音频文件。有什么解决方法吗?提前致谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。