Android Studio 文字转语音失败:未绑定到 TTS 引擎。
创始人
2024-08-16 21:30:17
0

问题描述: 在使用Android Studio开发中,尝试将文字转为语音时,出现了错误提示“未绑定到 TTS 引擎”。

解决方法: 该错误提示通常是由于未正确配置和初始化TTS引擎所导致的。以下是解决该问题的步骤和代码示例:

  1. 确保已在AndroidManifest.xml文件中添加了以下权限:




  1. build.gradle文件中添加以下依赖项:
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.speech.tts:android-tts:1.0.0'
  1. MainActivity.java文件中添加以下代码:
import android.speech.tts.TextToSpeech;

public class MainActivity extends AppCompatActivity implements TextToSpeech.OnInitListener {

    private TextToSpeech tts;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tts = new TextToSpeech(this, this);
    }

    @Override
    public void onInit(int status) {
        if (status == TextToSpeech.SUCCESS) {
            int result = tts.setLanguage(Locale.US);

            if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
                Log.e("TTS", "This Language is not supported");
            } else {
                // 将文字转为语音
                tts.speak("Hello World", TextToSpeech.QUEUE_FLUSH, null);
            }
        } else {
            Log.e("TTS", "Initialization Failed!");
        }
    }

    @Override
    protected void onDestroy() {
        if (tts != null) {
            tts.stop();
            tts.shutdown();
        }
        super.onDestroy();
    }
}

通过以上步骤和代码示例,应该能够解决“未绑定到 TTS 引擎”错误,并成功将文字转为语音。

相关内容

热门资讯

让我来分享经验!pokemmo... 让我来分享经验!pokemmo手机辅助软件,hhpoker底牌透视脚本,本来是有挂(的确有挂)1、免...
科技分享!wepoker私人局... 科技分享!wepoker私人局辅助,wpk插件,其实是有挂(证实有挂)1)辅助插件:进一步探索辅助大...
玩家必看!hhpoker有没有... 玩家必看!hhpoker有没有外挂,德州真人透视脚本,都是是真的有挂(有挂分享)辅助器是一种具有地方...
记者揭秘!wepokerplu... 记者揭秘!wepokerplus开挂,德普之星怎么设置埋牌,确实是真的有挂(有挂细节)1、这是跨平台...
教学盘点!佛手大菠萝辅助,we... 教学盘点!佛手大菠萝辅助,wepoker破解是真的还是假的,真是存在有挂(有挂技巧)1、下载好透视辅...
玩家科普!wepoker私人局... 玩家科普!wepoker私人局规律,hhpoker俱乐部是干嘛的,原来是有挂(有挂辅助)是不是有人用...
查到实测辅助!德州局透视,wp... 查到实测辅助!德州局透视,wpk辅助是什么,一贯存在有挂(有挂助手)1、完成辅助器v3.3的残局,帮...
玩家攻略推荐!wpk透视辅助,... 玩家攻略推荐!wpk透视辅助,wepoker国外版透视,总是有挂(确实有挂)1、下载好透视辅助下载之...
揭秘!wepoker作弊方法,... 揭秘!wepoker作弊方法,we-poker正规吗,一直存在有挂(有挂规律)1、这是跨平台的轻量版...
每日必备!hhpoker德州有... 每日必备!hhpoker德州有挂吗,wepoker辅助透视,真是真的是有挂(有挂规律)1、每一步都需...