can it speak texts in xamarin.forms?
I know there is TextToSpeech
TextToSpeech.SpeakAsync("你好");
but nothing happend.
@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
Have you tried specifying the locale (and other SpeechOptions properties)?
See https://docs.microsoft.com/en-us/xamarin/essentials/text-to-speech#speech-locales
@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
Failed to initialize Text to Speech engine.
@JohnHardman
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
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
@JohnHardman
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.
No. I am using 应用商店
@lescper
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.
你好
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.
Oh I see Then I can not use it.
I can use something to play a audio file right?