我正在使用来自https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/dependency-service/text-to-speech/的精确Android实现代码和相同的共享代码示例DependencyService.Get<ITextToSpeech>().Speak("Hello from Xamarin Forms");
问题是它适用于Visual Studio安卓模拟器和我的华为P9,但它不起作用(它编译,但它应该说话,而不是它保持沉默)在三星S6或我的朋友其他手机。有谁知道可能导致问题的原因?
[assembly: Dependency(typeof(TextToSpeechImplementation))]
namespace DependencyServiceSample.Droid
{
public class TextToSpeechImplementation : Java.Lang.Object, ITextToSpeech, TextToSpeech.IOnInitListener
{
TextToSpeech speaker;
string toSpeak;
public void Speak(string text)
{
toSpeak = text;
if (speaker == null)
{
speaker = new TextToSpeech(Forms.Context, this);
}
else
{
speaker.Speak(toSpeak, QueueMode.Flush, null, null);
}
}
public void OnInit(OperationResult status)
{
if (status.Equals(OperationResult.Success))
{
speaker.Speak(toSpeak, QueueMode.Flush, null, null);
}
}
}
}