我目前正在编写Azure认知服务教程,特别是Intent Recognition示例。当我在ConversationalLanguageUnderstandingModel
上使用IntentRecognizer
中的ApplyLanguageModels()
方法时,我遇到了一个System.AccessViolationException
。
下面是我的代码片段:
var speechConfig = SpeechConfig.FromSubscription(_speechKey, _speechRegion);
speechConfig.SpeechRecognitionLanguage = "en-US";
using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
// Creates an intent recognizer in the specified language using microphone as audio input.
using (var intentRecognizer = new IntentRecognizer(speechConfig, audioConfig))
{
var cluModel = new ConversationalLanguageUnderstandingModel(
_languageKey,
_languageEndpoint,
_cluProjectName,
_cluDeploymentName);
var collection = new LanguageUnderstandingModelCollection();
collection.Add(cluModel);
intentRecognizer.ApplyLanguageModels(collection);
错误发生在intentRecgonizer.ApplyLanguageModels(collection)
,堆栈跟踪显示:
Fatal error. System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
Repeat 2 times:
--------------------------------
at Microsoft.CognitiveServices.Speech.Internal.Recognizer.intent_recognizer_add_conversational_language_understanding_model(Microsoft.CognitiveServices.Speech.Internal.InteropSafeHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle, Microsoft.CognitiveServices.Speech.Internal.Utf8StringHandle)
--------------------------------
at Microsoft.CognitiveServices.Speech.Intent.IntentRecognizer.ApplyLanguageModels(Microsoft.CognitiveServices.Speech.Intent.LanguageUnderstandingModelCollection)
at IntentRecgonition+<DoWork>d__7.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
at IntentRecgonition.DoWork()
at Program+<Main>d__4.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
at System.Runtime.CompilerServices.AsyncTaskMethodBuilder.Start[[System.__Canon, System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]](System.__Canon ByRef)
at Program.Main(System.String[])
at Program.<Main>(System.String[])
我使用的是Azure Cognitive Services SDK版本1.28.0。(VS 2022 .NET 6控制台应用程序)
我已经检查了密钥、端点和部署名称,它们似乎都是正确的。我也试着把我的SDK更新到最新版本。然而,这些尝试都没有解决这个问题。
有没有人对这个System.AccessViolationException
有任何见解或解决方案?
先谢谢你的帮助。
1条答案
按热度按时间ffdz8vbo1#
我必须重新启动VS,因为我刚刚添加了所需的环境变量。