Android中从字符串数组到语音的文本转换?
我已经在Android Studio中创建了一个幻灯片应用程序,我希望将字符串转换为语音。 我该怎么做?请在队列刷新后查看speak()。 先谢谢你Android中从字符串数组到语音的文本转换?,android,Android,我已经在Android Studio中创建了一个幻灯片应用程序,我希望将字符串转换为语音。 我该怎么做?请在队列刷新后查看speak()。 先谢谢你 public class Level1 extends Activity { int i= 0; static final String[] texts ={"hi", "bear", "hat"}; TextToSpeech tts; @Override protected void onCreate(Bundle s
public class Level1 extends Activity {
int i= 0;
static final String[] texts ={"hi", "bear", "hat"};
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.level1);
tts = new TextToSpeech(Level1.this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US);
tts.speak(texts,TextToSpeech.QUEUE_FLUSH,????? ); //What do I put here?
} else {
Toast.makeText(getApplicationContext(),
"Feature not Supported in Your Device",
Toast.LENGTH_SHORT).show();
}
}
});
}
@Override
protected void onPause() {
if (tts!= null) {
tts.stop();
tts.shutdown();
}
super.onPause();
}
简单地把空放在那里
tts.speak(texts,TextToSpeech.QUEUE_FLUSH,null);
试试这个
编辑1:
使用OuttanceCompleteListener…一旦它完成调用hi,就会调用它…然后您可以从那里再次调用speak…这次更改方法
tts.speak(texts[1],TextToSpeech.QUEUE_ADD,null);
或者您可以简单地将字符串数组concate
tts.speak(texts[0]+" "+texts[1]+" "+texts[2],TextToSpeech.QUEUE_FLUSH,null);
它应该是空的
如果你想要更多的参考资料,你可以找到它
public int speak(字符串文本、int-queueMode、HashMap参数)
这里
参数-->
请求的参数。可以为空。支持的参数名称:KEY-PARAM-STREAM、KEY-PARAM-outrance-ID、KEY-PARAM-VOLUME、KEY-PARAM-PAN。可以传入特定于引擎的参数,但参数键的前缀必须是它们要用于的引擎的名称。例如,键“com.svox.pico_foo”和“com.svox.pico:bar”将被传递到名为“com.svox.pico”的引擎(如果正在使用)。你好,Meenal,谢谢你的帮助,但当我输入null时,我得到错误消息:TextToSpeech中的speak()无法应用于text:java.lang.String文本(java.lang.String[])我添加了字符串数组=文本[0];现在它说“嗨”。我怎么才能让它也说熊和帽子呢?
public class Level1 extends Activity {
int i= 0;
static final String[] texts ={"hi", "bear", "hat"};
TextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.level1);
tts = new TextToSpeech(Level1.this, new TextToSpeech.OnInitListener() {
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US);
tts.speak(texts,TextToSpeech.QUEUE_FLUSH,null); // ????--> null
} else {
Toast.makeText(getApplicationContext(),
"Feature not Supported in Your Device",
Toast.LENGTH_SHORT).show();
}
}
});
}
tts.speak(texts,TextToSpeech.QUEUE_FLUSH,null);
public int speak (String text, int queueMode, HashMap<String, String> params)