我想我会尽可能详细地设置这个,希望有人对这种设置有一些经验。
前端: ASP.Net MVC Razer 网站。
- .Net 框架 4.6.1
后端: Bot 框架 Web API (RESTful)。
- .Net 框架 4.6
后端:我使用各种位于 Azure 的认知服务,但在这种情况下,它只是 Bing Speech API。
相关SDK:
- Microsoft.Bing.Speech(版本:2.0.2)
- Bond.Core.CSharp(版本:8.0.0)~依赖
- Bond.CSharp (Version: 8.0.0) ~依赖
- Bond.Runtime.CSharp (Version: 8.0.0) ~依赖
我getUserMedia
在网站上使用一些 javascript 代码的请求来记录用户麦克风,这会创建一个 blob URL。
然后我将 blob url 作为 inContentUrl
传递Attachment
给Activity
.
当这遇到 Bot 框架时,我会进行一些基本验证(与此问题无关),然后传递给自定义Dialog<T>
.
这就是我努力让 Bing Speech API 做我想做的事情的地方。
我从内部使用此方法Dialog<T>
:
public async Task Run(string audioFile, string locale, Uri serviceUrl)
{
// create the preferences object
var preferences = new Preferences(locale, serviceUrl, new CognitiveServicesAuthorizationProvider(subscriptionKey));
using (var speechClient = new SpeechClient(preferences))
{
speechClient.SubscribeToPartialResult(this.OnPartialResult);
speechClient.SubscribeToRecognitionResult(this.OnRecognitionResult);
using (WebClient webClient = new WebClient())
{
using (Stream stream = webClient.OpenRead(audioFile))
{
var deviceMetadata = new DeviceMetadata(DeviceType.Near, DeviceFamily.Desktop, NetworkType.Ethernet, OsName.Windows, "1607", "Dell", "T3600");
var applicationMetadata = new ApplicationMetadata("SampleApp", "1.0.0");
var requestMetadata = new RequestMetadata(Guid.NewGuid(), deviceMetadata, applicationMetadata, "SampleAppService");
try
{
await speechClient.RecognizeAsync(new SpeechInput(stream, requestMetadata), this.cts.Token).ConfigureAwait(false);
}
catch (Exception genEx)
{
// Was just using this try/catch for debugging reasons
}
}
}
}
}
我正在使用 WebClient
来获取流,而不是 FileStream
此方法在 Microsoft 示例代码中使用的,因为 Filestream
不会从 URL 流式传输。
当前的问题:
当这条线被击中时:
await speechClient.RecognizeAsync(new SpeechInput(stream, requestMetadata), this.cts.Token).ConfigureAwait(false);
它引发有关 Bond.IO.dll 的错误
融合日志:
我在本地调试,Microsoft Bot Framework Emulator
这就是为什么你会看到本地文件路径。
=== Pre-bind state information ===
LOG: DisplayName = Bond.IO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
(Fully-specified)
LOG: Appbase = file:///[project folder]
LOG: Initial PrivatePath = \bin
Calling assembly : Microsoft.Bing.Speech, Version=2.0.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:\web.config
LOG: Using host configuration file: \aspnet.config
LOG: Using machine configuration file from \machine.config.
LOG: Post-policy reference: Bond.IO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
LOG: Attempting download of new URL file:///C:/Users/[USER]/AppData/Local/Temp/Temporary ASP.NET Files/vs/0f4bb63f/ca796715/Bond.IO.DLL.
LOG: Attempting download of new URL file:///C:/Users/[USER]/AppData/Local/Temp/Temporary ASP.NET Files/vs/0f4bb63f/ca796715/Bond.IO/Bond.IO.DLL.
LOG: Attempting download of new URL file:///C:/[USER]/[PROJECT PATH]/bin/Bond.IO.DLL.
WRN: Comparing the assembly name resulted in the mismatch: Major Version
ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
奇怪的是,如果我将 bing api 回滚到 2.0.1 并手动插入示例项目中安装的旧版本的 Bond.IO 包(版本 4.0.1),它不会抛出此错误,它会引发其他错误。
我真正要问的是:
如果我只想将 .wav 音频文件发送到我的 API,然后使用 Bing.Speech API 的转录功能将语音转换为文本,那么最好的方法是什么?我是否至少朝着正确的方向前进。
如果您的答案与我已经在做的事情有关,则可以加分。