微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

发生了 VSCode 异常:CLR/System.ApplicationException

如何解决发生了 VSCode 异常:CLR/System.ApplicationException

我正在 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

enter image description here

正确路径

C:/Users/Administrator/source/repos/vscodeConsole/narration.wav

enter image description here

隐私

看错误信息,第26行附近有错误。

You can test with my sample code。如果它运行正常,那么就是你的代码有问题。我初步判断是你的文件路径附近的代码不正常。

enter image description here

如果我的示例代码没有正常运行,可能是安装了VSCode(包括Extension)或者dotnet core导致的,需要进一步的TroubleShooting。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。