2014-01-29 147 views
0

我們正在Windows 8.1環境中開發應用程序。 我想實現Bing語音識別控制。 (See thisWindows 8.1 Bing語音識別控制 - 無效的媒體類型

該圖標顯示出來,我已經實施了代碼,如this解決方案。

這裏就是我在做的代碼背後

//When page is loaded 
private void ProblemenTest_Loaded(object sender, RoutedEventArgs e) 
{ 
    //Bing speech recognition initialiseren 
    var credentials = new SpeechAuthorizationParameters(); 
    credentials.ClientId = "myemail"; 
    credentials.ClientSecret = "mypass"; 

    // Initialize the speech recognizer. 
    SR = new SpeechRecognizer("en-US", credentials); 

    // Add speech recognition event handlers. 
    SR.AudioLevelChanged += SR_AudioLevelChanged; 
    SR.RecognizerResultReceived += SR_RecognizerResultReceived; 
} 

//Microphone button clicked event 
private async void BtnMicrofoon_Click(object sender, RoutedEventArgs e) 
{ 
    var result = await SR.RecognizeSpeechToTextAsync(); //Error here 
    txtProblem.Text = result.Text; 
} 

//When speech recognition has finished 
void SR_RecognizerResultReceived(SpeechRecognizer sender, 
    SpeechRecognitionResultReceivedEventArgs args) 
{ 
    if (args.Text == null) return; 
    txtProblem.Text = args.Text; 
} 

//When audioleven changed 
void SR_AudioLevelChanged(SpeechRecognizer sender, 
    SpeechRecognitionAudioLevelChangedEventArgs args) 
{ 
    var v = args.AudioLevel; 
    if (v > 0) VolumeMeter.Opacity = v/50; 
    else VolumeMeter.Opacity = Math.Abs((v - 50)/100); 
} 

當我按一下按鈕,我得到一個錯誤抱怨無效的介質類型。

error message

我應該在哪裏尋找這個錯誤的根源?

回答

2

在微軟員工Johannes Kebeck http://jkebeck.wordpress.com/和他2013年11月16日的帖子中,他遇到了同樣的問題,並且遇到了一個偉大的地理空間博客,他提到必須在你的package.appxmanifest中設置麥克風的設備功能已經想通了),但關鍵是您還必須允許三個DLL可激活。

要做到這一點,你只需要手動編輯文件(單擊鼠標右鍵,打開方式,選擇XML文本編輯器),然後添加下面的功能如下:

<Extensions> 
<Extension Category="windows.activatableClass.inProcessServer"> 
    <InProcessServer> 
    <Path>Microsoft.Speech.VoiceService.MSSRAudio.dll</Path> 
    <ActivatableClass ActivatableClas-sId="Microsoft.Speech.VoiceService.MSSRAudio.Encoder" ThreadingModel="both" /> 
    </InProcessServer> 
</Extension> 
<Extension Category="windows.activatableClass.proxyStub"> 
    <ProxyStub ClassId="5807FC3A-A0AB-48B4-BBA1-BA00BE56C3BD"> 
    <Path>Microsoft.Speech.VoiceService.MSSRAudio.dll</Path> 
    <Interface Name="IEncodingSettings" InterfaceId="C97C75EE-A76A-480E-9817-D57D3655231E" /> 
    </ProxyStub> 
</Extension> 
<Extension Category="windows.activatableClass.proxyStub"> 
    <ProxyStub ClassId="F1D258E4-9D97-4BA4-AEEA-50A8B74049DF"> 
    <Path>Microsoft.Speech.VoiceService.Audio.dll</Path> 
    <Interface Name="ISpeechVolumeEvent" InterfaceId="946379E8-A397-46B6-B9C4-FBB253EFF6AE" /> 
    <Interface Name="ISpeechStatusEvent" InterfaceId="FB0767C6-7FAA-4E5E-AC95-A3C0C4D72720" /> 
    </ProxyStub> 
</Extension> 
</Extensions> 

保存,重新編譯和你語音識別現在將起作用。

+0

謝謝,這可能是一個解決方案,但我很害怕我無法測試。 Bing語音控制在我的國家尚未提供(比利時)。奇怪的是,我甚至不能使用英文版而不是荷蘭語。我無法將我的Azure Marketplace帳戶完全註冊到應用程序中... 微軟在釋放他們的資源方面太慢了! – DerpyNerd

+0

您可以隨時查看System.Speech命名空間,該命名空間既執行識別器又執行綜合並且是免費的(.NET框架的一部分)。它可以同時進行聽寫和基於語法樹的聽力。代碼幾乎相同。在Windows 8/8.1下正常工作就不能存儲應用程序,因爲該庫似乎不適用於他們,因此必須使用Bing Speech Control。基本上類似,但限於查詢次數,需要互聯網進行識別。我與System.Speech一起去,因爲我不想要一個互聯網連接,並確定與WPF應用程序,而不是存儲應用程序。 – imaginasean