Lisa
Lisa

Reputation: 540

How to play IMFMediaEngine background audio while SpeechSynthesizer is playing

I want to play Windows Phone 8's Speech Synthesizer while background audio is playing. But every time, I activate the Speech Synthesizer, the background audio stops playing, and resumes after the synthesizer finishes.

Any suggestions? Thanks.

Some code snippets below: Background Audio: using IMFMediaEngine in C++, plays successfully.

Microsoft::WRL::ComPtr<IMFMediaEngine> m_mediaEngine;
m_mediaEngine->Play();

In C# / XAML, I have a XAML page with a button, when I click on it, it plays from WP8's latest Speech classes. Plays the text.

using Windows.Phone.Speech.Synthesis; 


public async void SpeakText(string text)
{
    SpeechSynthesizer speechSynthesizer = new SpeechSynthesizer();
    await speechSynthesizer.SpeakTextAsync(text);
}

I tried putting the SpeakTextAsync through threads, but I guess I'm doing it all wrong, because I still can't get both audio playing at the same time.

    private void bubble_Click(object sender, RoutedEventArgs e)
    {
       App.Manager.SpeakText("hello how are you");

// TRY 1: plays text only, background doesn't play
       //new Thread(() =>
       //{
       //    App.Manager.SpeakText(chinese);
       //}).Start();

// TRY 2: plays text only, background doesn't play
       //Deployment.Current.Dispatcher.BeginInvoke(() =>
       //{
       //    App.Manager.SpeakText(chinese);
       //});

// TRY 3: plays text only, background doesn't play
       //ThreadPool.QueueUserWorkItem(new WaitCallback(SpeakTextProc));

   }

   private void SpeakTextProc(Object stateInfo)
   {
      App.Manager.SpeakText("Hello how are you");
   }

Upvotes: 2

Views: 917

Answers (1)

Jeremiah Isaacson
Jeremiah Isaacson

Reputation: 340

On Windows Phone 7, I was able to get two separate audio streams using XNA but seeing how that XNA isn't supported for further development on Windows Phone 8, that's not a great solution for you good luck.

Upvotes: 0

Related Questions