c# - VSCode 发生异常 : CLR/System. ApplicationException

标签 c# azure exception visual-studio-code speech-to-text

我正在 VSCode 中使用 C# 开发语音转文本模型。该模型正确转录第一个文件。当我添加新文件并尝试转录时,出现以下错误:

发生异常:CLR/System.ApplicationException System.Private.CoreLib.dll 中发生“System.ApplicationException”类型的异常,但未在用户代码中处理:“错误代码异常: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 语音配置,AudioConfig 音频配置) 在 C:\Users\admin\source\repos\AI-102-Process-Speech-master\transcribe_speech_to_text\csharp\NEST\Program.cs 中的 NEST.Program.d__1.MoveNext() 处:第 26 行 在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.GetResult() 在 C:\Users\admin\source\repos\AI-102-Process-Speech-master\transcribe_speech_to_text\csharp\NEST\Program.cs 中的 NEST.Program.d__0.MoveNext() 处:第 12 行

await RecognizeSpeechAsync();部分是异常发生的地方(第 12 行)。 第 26 行使用 (var recognizer = 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 导致的,需要进一步排查。

关于c# - VSCode 发生异常 : CLR/System. ApplicationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66568090/

相关文章:

c# - 如何使用 azure .net SDK 或 Fluent API 验证 ARM 模板?

zend-framework - "Uncaught exception"不顾一切

java - 异常处理

c# - 使用 Task<bool> 返回类型对异步方法进行单元测试

c# - 如何从 C# 中的 Action 委托(delegate)中删除方法

azure - 如何在另一个资源组中引用 SQL Server

azure - 如何使用系统分配的托管标识保护 Azure Function

java - 将方法更改为java中的运行时异常

c# - 收据打印的中心文本

c# - MonoMac WebView - 显示控制台或 Web 检查器?