如何获取要在 Azure 语音转文本模型中生成的时间戳?
How do I get timestamps to generate in Azure speech to text model?
我正在尝试使用 Azure 的语音转文本代码生成和收集数据。我想生成时间戳,减少输出中的冗余,并导出到 Excel。下面的代码 运行s 没有错误:
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();
//calls the audio file
using (var audioInput = AudioConfig.FromWavFileInput("C:/Users/MichaelSchwartz/source/repos/AI-102-Process-Speech-master/transcribe_speech_to_text/media/narration.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.");
};
recognizer.Recognized += (s, e) =>
{
var j = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
};
// 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);
// Stops recognition.
await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
}
}
}
}
当我 运行 它时,我没有看到时间戳数据。如何生成时间戳数据?
此外,有没有办法消除输出中的冗余?示例:
RECOGNIZING: Text=the
RECOGNIZING: Text=the speech
RECOGNIZING: Text=the speech translation
RECOGNIZING: Text=the speech translation API
RECOGNIZING: Text=the speech translation API transcribes
RECOGNIZING: Text=the speech translation API transcribes audio
我只想要最后的结果。有没有办法在保持准确性的同时从输出中删除“RECOGNIZING:”数据?提前致谢!
删除"RECOGNIZING:"
,只需删除这句话:
recognizer.Recognizing += (s, e) =>
{
Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
};
我没有看到您将结果和时间戳导出到 Excel 的位置。您可以在获得 SpeechRecognitionResult
对象后使用此代码:
var json = result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
Console.WriteLine(json);
输出结果为:
我正在尝试使用 Azure 的语音转文本代码生成和收集数据。我想生成时间戳,减少输出中的冗余,并导出到 Excel。下面的代码 运行s 没有错误:
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();
//calls the audio file
using (var audioInput = AudioConfig.FromWavFileInput("C:/Users/MichaelSchwartz/source/repos/AI-102-Process-Speech-master/transcribe_speech_to_text/media/narration.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.");
};
recognizer.Recognized += (s, e) =>
{
var j = e.Result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
};
// 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);
// Stops recognition.
await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
}
}
}
}
当我 运行 它时,我没有看到时间戳数据。如何生成时间戳数据?
此外,有没有办法消除输出中的冗余?示例:
RECOGNIZING: Text=the
RECOGNIZING: Text=the speech
RECOGNIZING: Text=the speech translation
RECOGNIZING: Text=the speech translation API
RECOGNIZING: Text=the speech translation API transcribes
RECOGNIZING: Text=the speech translation API transcribes audio
我只想要最后的结果。有没有办法在保持准确性的同时从输出中删除“RECOGNIZING:”数据?提前致谢!
删除"RECOGNIZING:"
,只需删除这句话:
recognizer.Recognizing += (s, e) =>
{
Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
};
我没有看到您将结果和时间戳导出到 Excel 的位置。您可以在获得 SpeechRecognitionResult
对象后使用此代码:
var json = result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
Console.WriteLine(json);
输出结果为: