Forum Xamarin.Forms

how to speak text in xamarin.forms?

lescperlescper Member ✭✭✭✭✭
edited February 20 in Xamarin.Forms

can it speak texts in xamarin.forms?

I know there is TextToSpeech

TextToSpeech.SpeakAsync("你好");

but nothing happend.

Tagged:

Best Answer

  • JohnHardmanJohnHardman GBUniversity admin
    Accepted Answer

    @LeonLu said:
    Is there a Google play service on your device? And change your device's language to Chinese.

    That raises an interesting question. Is the Android version of the Xamarin Forms Essentials' TextToSpeech dependent upon having access to Google Play Services? If so, that might mean that the feature cannot be used in some parts of the world where access to Google Play Store is restricted. If that's the case, that should probably be included in the TextToSpeech documentation.

Answers

  • JohnHardmanJohnHardman GBUniversity admin
    edited February 20

    @lescper said:
    can it speak texts in xamarin.forms?

    I know there is TextToSpeech

    TextToSpeech.SpeakAsync("你好");

    but nothing happend.

    Have you tried specifying the locale (and other SpeechOptions properties)?
    See https://docs.microsoft.com/en-us/xamarin/essentials/text-to-speech#speech-locales

  • lescperlescper Member ✭✭✭✭✭

    @JohnHardman I can not use Continuswith to GetLocaclesAsync
    and If I not do this there will be an error that failed to initialize the TextToSpeech

  • lescperlescper Member ✭✭✭✭✭

    Failed to initialize Text to Speech engine.

  • lescperlescper Member ✭✭✭✭✭
  • JohnHardmanJohnHardman GBUniversity admin

    @lescper said:
    @JohnHardman I can not use Continuswith to GetLocaclesAsync
    and If I not do this there will be an error that failed to initialize the TextToSpeech

    To investigate your original question, hardcode the locale and other SpeechOptions temporarily, and make sure that any calls to TextToSpeech are done sequentially on one thread. There's no point doing anything more complex until the simplest case works. Stick with simple use of await rather than adding ContinuesWith and ConfigureAwait when doing the initial test.

    If that works, the next step will be to get hold of the locale rather than hardcoding it.

    Only after that works, would I try to do anything more complex. My guess is that you have two things going on currently, a need to specify the locale (and possibly other SpeechOptions), and possibly a threading issue. There's no way of knowing though until the simple test is done

  • lescperlescper Member ✭✭✭✭✭

    I tried that use await instead of ContinuesWith it is not work.

    and I put the code to mainactivity to put get the locale and save it to a static variale

    it still can not work.

    failed to initialize the text speech engine

  • lescperlescper Member ✭✭✭✭✭
  • LeonLuLeonLu Member, Xamarin Team Xamurai

    Is there a Google play service on your device? And change your device's language to Chinese.


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • lescperlescper Member ✭✭✭✭✭

    No. I am using 应用商店

  • JohnHardmanJohnHardman GBUniversity admin

    @lescper

    @LeonLu said:
    Is there a Google play service on your device?

    If you put Japanese text into the Google Text-to-Speech app at
    https://play.google.com/store/apps/details?id=com.google.android.tts&hl=en_GB&gl=US
    is it spoken on your device correctly?

    If so, that tells us that your device is set up correctly.

    你好

  • JohnHardmanJohnHardman GBUniversity admin
    Accepted Answer

    @LeonLu said:
    Is there a Google play service on your device? And change your device's language to Chinese.

    That raises an interesting question. Is the Android version of the Xamarin Forms Essentials' TextToSpeech dependent upon having access to Google Play Services? If so, that might mean that the feature cannot be used in some parts of the world where access to Google Play Store is restricted. If that's the case, that should probably be included in the TextToSpeech documentation.

  • lescperlescper Member ✭✭✭✭✭

    Oh I see Then I can not use it.

    I can use something to play a audio file right?

Sign In or Register to comment.