首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >印尼语文本到语音

印尼语文本到语音
EN

Stack Overflow用户
提问于 2020-01-27 11:14:40
回答 2查看 149关注 0票数 1

我有印尼文本到语音的问题,这是我的代码

代码语言:javascript
复制
public class ButtonListener {

private final TextToSpeech mTextToSpeech;
private final DictionaryFragment mDictionaryFragment;
private final DictionaryTypeState mDictionaryTypeState;

@BindView(R.id.search_words)
EditText mEditText;

public ButtonListener(DictionaryFragment dictionary, View root) {
    ButterKnife.bind(this, root);
    this.mDictionaryFragment = dictionary;
    this.mTextToSpeech = new TextToSpeech(dictionary.getContext(), null);
    this.mDictionaryTypeState = new DictionaryTypeState(dictionary.getContext());


}

@OnClick(R.id.clear_text)
void clearText() {
    mEditText.setText(ConstanValues.EMPTY);
    mTextToSpeech.stop();
}

@OnClick(R.id.speech_to_text)
void voiceInput() {
    openVoiceInput();
}

@OnClick(R.id.text_to_speech)
void speakText() {
    mTextToSpeech.setLanguage(getLangue());
    mTextToSpeech.speak(mEditText.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
}

private final Locale getLangue() {

    return mDictionaryTypeState.getDictionarySourceState().equals(ConstanValues.ENGLISH_SOURCE)
            ? Locale.ENGLISH : new Locale("id", "ID");
}

private final void openVoiceInput() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
            .putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
            .putExtra(RecognizerIntent.EXTRA_LANGUAGE, new Locale("id", "ID"))
            .putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word");
    mDictionaryFragment.startActivityForResult(intent, ConstanValues.REQUEST_CODE);
}

public TextToSpeech getTextToSpeech() {
    return mTextToSpeech;
}

}

我做了一个字典应用程序,可以使用英语和印尼语文本进行语音转换,我为印尼语编写了代码,但模拟器中显示的总是英语,我的代码中是否缺少什么?我恳求你的帮助

EN

回答 2

Stack Overflow用户

发布于 2020-01-27 13:28:51

您需要使用该语言将文本初始化为语音

下面是你如何做到这一点。

代码语言:javascript
复制
     textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
     @Override
     public void onInit(int status) {
         switch (status) {
             case TextToSpeech.SUCCESS: {
                 synchronized (this) {
                         int result = textToSpeech.setLanguage(<set the indonesia id here>);
                  <Take action based on the result of initialisation>

                 }
             }
             break;
             default: {
                 Toast.makeText(appContext, appContext.getResources().getString(R.string.tts_init_failed), Toast.LENGTH_LONG).show();
             }
             break;
         }
     }
 });
票数 2
EN

Stack Overflow用户

发布于 2020-01-27 13:46:22

尝试使用更改代码中的语言的方法来执行此代码

代码语言:javascript
复制
 Locale locale = new Locale("id");
    Locale.setDefault(locale);
    Configuration config = getBaseContext().getResources().getConfiguration();
    config.locale = locale;
    getBaseContext().getResources().updateConfiguration(config,
    getBaseContext().getResources().getDisplayMetrics());

您可以在this链接中找到区域设置数据线

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59924796

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档