如何使用 Azure 语音转文本和 C# 生成时间戳?

How to generate timestamps using Azure speech to text and C#?

我正在尝试在 C# 中使用 Azure S2T 生成时间戳。我尝试了以下资源:

How to get Word Level Timestamps using Azure Speech to Text and the Python SDK?

How to generate timestamps in speech recognition?

第二个最有帮助,但我仍然遇到错误。我的代码是:

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',因为它是 'method group' [NEST]

名称'result'在当前上下文[NEST]中不存在

如何解决这些错误?

你应该使用

config.RequestWordLevelTimestamps()

而不是

config.RequestWordLevelTimestamps = true;

RequestWordLevelTimestamps 是一种方法。 Reference to the method.