Espeak读取单独的字母而不是单词

问题描述 投票:1回答:1

我第一次尝试在以下代码中使用Google的默认TTS引擎,但我发现,不支持波斯语!

所以,我在手机上下载并安装了espeak RedZoc TTS engine,并将默认的TTS语言更改为波斯语。当我在手机设置或RedZoc应用程序内部检查时,它运行良好。

但是,当我在手机中运行我的代码时,它会单独读取这些字母,而不是阅读完整的单词! (例如它应该说SALAM但它说Arabic Sin Lam Alef Mim

主要内容:

package com.m.ttsapp;

import android.content.Intent;
import android.speech.tts.TextToSpeech;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.util.Locale;

public class MainActivity extends AppCompatActivity
{
    String text;
    EditText et;
    TextToSpeech tts;
    Button btn;


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

        et=findViewById(R.id.editText1);
        btn = findViewById(R.id.button1);

        tts=new TextToSpeech(MainActivity.this, new TextToSpeech.OnInitListener() {


            @Override
            public void onInit(int status)
            {
                if(status == TextToSpeech.SUCCESS)
                {
                    int result=tts.setLanguage(Locale.);
                    if(result==TextToSpeech.LANG_MISSING_DATA || result==TextToSpeech.LANG_NOT_SUPPORTED)
                    {
                        Log.e("error", "This Language is not supported");
                    }
                    else{
                        ConvertTextToSpeech();
                    }
                }
                else
                    Log.e("error", "Initilization Failed!");
            }
        });

        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ConvertTextToSpeech();

            }
        });

    }

    @Override
    protected void onPause()
    {

        if(tts != null)
        {

            tts.stop();
            tts.shutdown();
        }
        super.onPause();
    }


    private void ConvertTextToSpeech()
    {
        text = et.getText().toString();
        if(text == null || "".equals(text))
        {
            text = "Content not available";
            tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
        }else
            tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
    }


}

我知道也许我必须改变这行代码,但不知道改变它是什么? int result=tts.setLanguage(Locale.);

或许我必须忘记所有这些代码并写下另一个?但是怎么样?

android locale text-to-speech persian espeak
1个回答
1
投票

没有'内置'Locale.PERSIAN,因此您需要创建Locale。

final Locale persianLocale = new Locale("fa","IR");

然后设置它:

tts.setLanguage(persianLocale);
© www.soinside.com 2019 - 2024. All rights reserved.