Azure 语音转文本模型运行但 returns 错误输出
Azure speech to text model runs but returns wrong output
我正在尝试 运行 在 Visual Studio 中使用 Azure 和 C# 将语音转换为文本模型 代码遵循以下说明:https://docs.microsoft.com/en-us/learn/modules/transcribe-speech-input-text/5-exercise-convert-speech-from-audio-file?pivots=csharp
认知服务已安装。音频文件路径已正确标记。我输入了正确的订阅密钥和服务区域(出于隐私考虑在此处进行了编辑)。关联的 json 文件中的项目文件路径是正确的。我的代码是:
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
namespace SpeechToTextCsharp
{
class Program
{
static async Task Main(string[] args)
{
await RecognizeSpeechAsync();
}
static async Task RecognizeSpeechAsync()
{
// Configure the subscription information for the service to access.
// Use either key1 or key2 from the Speech Service resource you have created
var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
// Setup the audio configuration, in this case, using a file that is in local storage.
using (var audioInput = AudioConfig.FromWavFileInput("../narration.wav"))
// Pass the required parameters to the Speech Service which includes the configuration information
// and the audio file name that you will use as input
using (var recognizer = new SpeechRecognizer(config, audioInput))
{
Console.WriteLine("Recognizing first result...");
var result = await recognizer.RecognizeOnceAsync();
switch (result.Reason)
{
case ResultReason.RecognizedSpeech:
// to the terminal window
Console.WriteLine($"We recognized: {result.Text}");
break;
case ResultReason.NoMatch:
// No recognizable speech found in the audio file that was supplied.
// Out an informative message
Console.WriteLine($"NOMATCH: Speech could not be recognized.");
break;
case ResultReason.Canceled:
// Operation was cancelled
// Output the reason
var cancellation = CancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
break;
}
}
}
}
}
运行没有错误,但返回的输出是“Hello World!”。 narration.wav 文件不包含单词 hello world。由于没有返回任何错误,这很难诊断,互联网搜索也没有返回任何有用的信息。
如何转录音频文件?
您可能放错了 narration.wav 文件。或者程序读取包含 Hello world.
的音频文件
再次确认narration.wav文件的存放路径。根据你的代码../narration.wav
,你的文件应该存放在截图所示的地方
如果你把你的wav文件放在project中,可以用../../../narration.wav
来测试
我正在尝试 运行 在 Visual Studio 中使用 Azure 和 C# 将语音转换为文本模型 代码遵循以下说明:https://docs.microsoft.com/en-us/learn/modules/transcribe-speech-input-text/5-exercise-convert-speech-from-audio-file?pivots=csharp
认知服务已安装。音频文件路径已正确标记。我输入了正确的订阅密钥和服务区域(出于隐私考虑在此处进行了编辑)。关联的 json 文件中的项目文件路径是正确的。我的代码是:
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
namespace SpeechToTextCsharp
{
class Program
{
static async Task Main(string[] args)
{
await RecognizeSpeechAsync();
}
static async Task RecognizeSpeechAsync()
{
// Configure the subscription information for the service to access.
// Use either key1 or key2 from the Speech Service resource you have created
var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourServiceRegion");
// Setup the audio configuration, in this case, using a file that is in local storage.
using (var audioInput = AudioConfig.FromWavFileInput("../narration.wav"))
// Pass the required parameters to the Speech Service which includes the configuration information
// and the audio file name that you will use as input
using (var recognizer = new SpeechRecognizer(config, audioInput))
{
Console.WriteLine("Recognizing first result...");
var result = await recognizer.RecognizeOnceAsync();
switch (result.Reason)
{
case ResultReason.RecognizedSpeech:
// to the terminal window
Console.WriteLine($"We recognized: {result.Text}");
break;
case ResultReason.NoMatch:
// No recognizable speech found in the audio file that was supplied.
// Out an informative message
Console.WriteLine($"NOMATCH: Speech could not be recognized.");
break;
case ResultReason.Canceled:
// Operation was cancelled
// Output the reason
var cancellation = CancellationDetails.FromResult(result);
Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");
if (cancellation.Reason == CancellationReason.Error)
{
Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
Console.WriteLine($"CANCELED: Did you update the subscription info?");
}
break;
}
}
}
}
}
运行没有错误,但返回的输出是“Hello World!”。 narration.wav 文件不包含单词 hello world。由于没有返回任何错误,这很难诊断,互联网搜索也没有返回任何有用的信息。
如何转录音频文件?
您可能放错了 narration.wav 文件。或者程序读取包含 Hello world.
的音频文件再次确认narration.wav文件的存放路径。根据你的代码../narration.wav
,你的文件应该存放在截图所示的地方
如果你把你的wav文件放在project中,可以用../../../narration.wav
来测试