- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在 android 上的文本到语音引擎有一个奇怪的行为:
当我在我的 Galaxy S5 上测试文本转语音时,一切正常,音频以土耳其语和德语播放。
在其他一些手机(例如 LG 手机)上,textToSpeech 也可以正常工作 - 除了以下情况:
问题是我没有收到任何错误消息 - TTS 似乎已正常初始化。
任何提示将不胜感激!
这是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().setLogo(R.drawable.anne_eli_icons_pfeile_zurueck_weiss_17px);
getActionBar().setHomeButtonEnabled(true);
textToSpeech = new TextToSpeech(this, this);
}
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
log("onInit()");
int result = textToSpeech.setLanguage(new Locale(getTransLanguage()));
log("result:" + result);
textToSpeech.setSpeechRate(1.2f); // set speech speed rate
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Tools.showToast(this, "Language " + getTransLanguage() + " is not supported! Error code: " + result);
Intent installIntent = new Intent();
installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
} else {
speechEnabled = true;
}
} else {
speechEnabled = false;
Tools.showToast(this, "Text to speech initialization failed!");
}
}
最佳答案
之前,检查TTS服务是否可用:
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
/**
* This class demonstrates checking for a TTS engine, and if one is
* available it will spit out some speak.
*/
public class Main extends Activity implements TextToSpeech.OnInitListener
{
private TextToSpeech mTts;
// This code can be any value you want, its just a checksum.
private static final int MY_DATA_CHECK_CODE = 1234;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Fire off an intent to check if a TTS engine is installed
Intent checkIntent = new Intent();
checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(checkIntent, MY_DATA_CHECK_CODE);
}
/**
* Executed when a new TTS is instantiated. Some static text is spoken via TTS here.
* @param i
*/
public void onInit(int i)
{
mTts.speak("Hello folks, welcome to my little demo on Text To Speech.",
TextToSpeech.QUEUE_FLUSH, // Drop all pending entries in the playback queue.
null);
}
/**
* This is the callback from the TTS engine check, if a TTS is installed we
* create a new TTS instance (which in turn calls onInit), if not then we will
* create an intent to go off and install a TTS engine
* @param requestCode int Request code returned from the check for TTS engine.
* @param resultCode int Result code returned from the check for TTS engine.
* @param data Intent Intent returned from the TTS check.
*/
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == MY_DATA_CHECK_CODE)
{
if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS)
{
// success, create the TTS instance
mTts = new TextToSpeech(this, this);
}
else
{
// missing data, install it
Intent installIntent = new Intent();
installIntent.setAction(
TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(installIntent);
}
}
}
/**
* Be kind, once you've finished with the TTS engine, shut it down so other
* applications can use it without us interfering with it :)
*/
@Override
public void onDestroy()
{
// Don't forget to shutdown!
if (mTts != null)
{
mTts.stop();
mTts.shutdown();
}
super.onDestroy();
}
关于android - TextToSpeech android 构建版本不播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26910749/
对于 Android 上的新 TextToSpeech 实例,我遇到了 onInit(..) 的意外问题。 我发现的所有代码示例都假定在调用 onOnit(..) 之前将新实例返回给调用者,以便返回值
我试着像这样使用它 int result2 = tts_hebrew.setLanguage(Locale.iw); 但我无法识别为 Locale.iw。 在http://developer.andr
更新:经过一番挖掘,我设法在 Logcat 中找到了一些信息。见底部。 编辑 2:我现在从头开始创建了一个新 Activity 来减少这个问题。它仍然不能正常工作。这是代码: public class
我正在尝试在不同的类中调用 TextToSpeech。这是我的类(class)现在的样子: //MainActivity.java public class MainActivity extends
我正在创建一个涉及短信的 Android 应用程序,其中一个功能是输入时会读出每个字母。我正在使用TextToSpeech。 我让它在一个测试项目中工作,但是当将它集成到我自己的项目中时,我收到一个未
我正在使用 TextToSpeech 向我的联系人中的某人发送短信。我使用一种非常丑陋的方式来做到这一点,因为我需要以一种方式说出所有表达式“发送消息到联系人短信是你好”。最好是像“发送消息”这样的应
我的安卓应用因为这个原因被亚马逊拒绝了。 当电话打进来时,我正在播放这个 TextToSpeech。他们要我停止播放。我该怎么做? 最佳答案 在实现 TextToSpeech 的服务或 Activit
我的应用程序正在调用广播接收器来读取传入的文本消息并大声说出来。我的 Broadcast Receiver 被正确调用,它正确读取文本消息,但是当涉及到 speak() 方法时,它就崩溃了。这是我的代
我有一个刷新的文本,每次都会发生这种情况。 我调用位于另一个具有以下结构的类中的静态方法方法speak(): public class Voc { static TextToSpeech my
由于内存不足的情况(在程序中,而不是程序员),我的应用程序一直在崩溃。 MAT 显示我的 Activity 的副本有时会在屏幕旋转时保留下来,并且唯一使伪造副本保持 Activity 状态的对象是每个
我希望能够将文本中的语音更改为语音 API,例如更改: 从女性到男性的声音。 让声音更清晰 改变语速 如果可能的话,请有人告诉我。谢谢。 最佳答案 您可以通过 addSpeech() 为特定字符串提供
我正在 TextToSpeech 上创建一个应用程序。但是当我试图运行时,它会在下一行抛出异常。 tts.speak(ruleOne, TextToSpeech.QUEUE_ADD, null); H
我正在使用下面的库来实现 TextToSpeech 功能来说话 - 'net.gotev:speech:1.3.1' 现在我需要将所有国家/地区的口音更改为我尝试过的美国英语 - Speech.get
使用 Android TextToSpeech 时,有什么方法可以指定语音的性别,例如 tts.setGender(TextToSpeech.MALE)或 tts.speak("Hello ") ?
@SuppressWarnings("deprecation") private void saveAudio(String text) { HashMap myHashRender = ne
The bounty在2天后过期。这个问题的答案有资格获得+50声望奖励。 Nerdy Bunz希望引起更多关于此问题的注意。 作为一项实验,以及一种迫使我自己了解tts在Android上工作原理的方
我是 Java 新手 我正在尝试使用 TextToSpeech,我有 Referenced libraries还有这个.java code通过具体的例子。 我的Main.java: package m
我需要调用synthesizeToFile来创建一些音频文件,并且我需要知道它何时完成创建所有这些文件,以便通知用户。 我已经阅读了其他问题,但没有找到适合我的问题,或者该问题与 speak 功能相关
我在onUteranceComplete()中连续调用文本转语音speak()方法,当事件发生时。说话方法工作正常,它不断地朗读文本,但我在这段代码中遇到了一个奇怪的问题。 Activity 结束后,
我试图做一些非常简单的事情,或者我认为它是。 在我的蓝牙聊天中,我设置了 public static boolean potato = false; 在我的 MainActivity 的 onCrea
我是一名优秀的程序员,十分优秀!