Question

We're developing an app in Windows 8.1 environment. I wanted to implement the Bing Speech Recognition Control. (See this)

The icon is showing up and I've implemented the code like this solution.

Here's what I did in code behind

//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);
}

When I click the button, I get an error complaining about an invalid media type.

error message

Where should I look for the source of this error?

Was it helpful?

Solution

Was having the same issue and came across a great geospatial blog from Microsoft employee Johannes Kebeck http://jkebeck.wordpress.com/ and in his post dated November 16, 2013, he mentioned having to set the device capabilities for microphone in your package.appxmanifest (which I had already figured out) but the key was that you also have to allow three DLLs to be activatable.

To do this you just have to manually edit the file (right-click, Open With..., Select XML Text Editor) then add the following below capabilities:

<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>

Save, recompile and your speech recognition will now work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top