我正在 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
正确路径
C:/Users/Administrator/source/repos/vscodeConsole/narration.wav
隐私
查看错误信息,第26行附近有错误。
You can test with my sample code 。如果运行正常,那就是你的代码有问题。我初步判断是你的文件路径附近的代码出现异常。
如果我的示例代码无法正常运行,可能是由于安装了 VSCode(包括 Extension)或 dotnet core 导致的,需要进一步排查。
关于c# - VSCode 发生异常 : CLR/System. ApplicationException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66568090/