我正在尝试使用C#中的Azure S2T生成时间戳。我尝试了以下资源:
如何使用Azure Speech to Text和Python SDK获得Word级别的时间戳?
如何在语音识别中生成时间戳?
第二个是最有用的,但我仍然会出错。我的代码是:
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
namespace NEST
{
internal class NewBaseType
{
static async Task Main(string[] args)
{
// Creates an instance of a speech config with specified subscription key and region.
// Replace with your own subscription key and service region (e.g., "westus").
var config = SpeechConfig.FromSubscription("subscriptionkey", "region");
// Generates timestamps
config.OutputFormat = OutputFormat.Detailed;
config.RequestWordLevelTimestamps = true;
//calls the audio file
using (var audioInput = AudioConfig.FromWavFileInput("C:/Users/MichaelSchwartz/source/repos/AI-102-Process-Speech-master/transcribe_speech_to_text/media/Zoom_audio.wav"))
// Creates a speech recognizer from microphone.
using (var recognizer = new SpeechRecognizer(config, audioInput))
{
// Subscribes to events.
recognizer.Recognizing += (s, e) =>
{
Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
};
recognizer.Recognized += (s, e) =>
{
var result = e.Result;
Console.WriteLine($"Reason: {result.Reason.ToString()}");
if (result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"Final result: Text: {result.Text}.");
}
};
recognizer.Canceled += (s, e) =>
{
Console.WriteLine($"n Canceled. Reason: {e.Reason.ToString()}, CanceledReason: {e.Reason}");
};
recognizer.SessionStarted += (s, e) =>
{
Console.WriteLine("n Session started event.");
};
recognizer.SessionStopped += (s, e) =>
{
Console.WriteLine("n Session stopped event.");
};
// Starts continuous recognition.
// Uses StopContinuousRecognitionAsync() to stop recognition.
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
do
{
Console.WriteLine("Press Enter to stop");
} while (Console.ReadKey().Key != ConsoleKey.Enter);
var json = result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
Console.WriteLine(json);
// Stops recognition.
await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
}
}
}
}
返回的错误为:
无法分配给"RequestWordLevelTimestamps",因为它是"方法组"[NEST]
名称"result"在当前上下文[NEST]中不存在
如何解决这些错误?
您应该使用
config.RequestWordLevelTimestamps()
而不是
config.RequestWordLevelTimestamps = true;
RequestWordLevelTimestamps是一种方法。方法参考。