问题描述
我正在 VSCode 中使用 C# 开发 Speech to Text 模型。该模型正确转录了第一个文件。当我添加新文件并尝试转录时,出现以下错误:
发生异常:CLR/System.ApplicationException System.Private.CoreLib.dll 中发生类型为“System.ApplicationException”的异常,但未在用户代码中处理:“Exception with an error code: 0x8 (SPXERR_FILE_OPEN_Failed)” 在 Microsoft.CognitiveServices.Speech.Internal.SpxExceptionThrower.ThrowIfFail(IntPtr hr) 在 Microsoft.CognitiveServices.Speech.Recognizer.FromConfig(GetRecognizerFromConfigDelegate fromConfig、SpeechConfig 语音配置、AudioConfig 音频配置) 在 Microsoft.CognitiveServices.Speech.SpeechRecognizer..ctor(SpeechConfig speechConfig,AudioConfig audioConfig) 在 nesT.Program.d__1.MoveNext() 在 C:\Users\admin\source\repos\AI-102-Process-Speech-master\transcribe_speech_to_text\csharp\nesT\Program.cs:line 26 在 System.Runtime.ExceptionServices.ExceptiondispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 System.Runtime.CompilerServices.TaskAwaiter.GetResult() 在 nesT.Program.d__0.MoveNext() 在 C:\Users\admin\source\repos\AI-102-Process-Speech-master\transcribe_speech_to_text\csharp\nesT\Program.cs:line 12
await RecognizeSpeechAsync();部分是发生异常的地方(第 12 行)。 第 26 行正在使用 (varrecorder = new SpeechRecognizer(config,audioInput))。
我的代码是:
using System;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
namespace nesT
{
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("subscriptionkeyx","regionx");
// Setup the audio configuration,in this case,using a file that is in local storage.
using (var audioInput = AudioConfig.FromWavFileInput("C:/Users/admin/source/repos /AI-102-Process-Speech-master/transcribe_speech_to_text/media/whatstheweatherlike.wav"))
// Pass the required parameters to the Speech Service which includes the configuration
// 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();
提前致谢。
解决方法
SPXERR_FILE_OPEN_FAILED
表示找不到文件或打开失败。
我在文件路径中添加了一个空格来重现您的问题。 (您使用的是绝对路径。)
错误路径:
C:/Users/Administrator/source/repos /vscodeConsole/narration.wav
正确路径
C:/Users/Administrator/source/repos/vscodeConsole/narration.wav
隐私
看错误信息,第26行附近有错误。
You can test with my sample code。如果它运行正常,那么就是你的代码有问题。我初步判断是你的文件路径附近的代码不正常。
如果我的示例代码没有正常运行,可能是安装了VSCode(包括Extension)或者dotnet core导致的,需要进一步的TroubleShooting。