谷歌tts使用粤语读出内容

//使用粤语
Locale locale = new Locale(“yue”,”HKG”);
为什么不是
Locale locale = new Locale(“zh”,”HK”);
我也很奇怪,我是log打印出来看它有什么,再自己找的

之后也找到一些资料
这是关于语言的
ISO 639-3 Macrolanguage Mappings
资料在 http://www-01.sil.org/iso639-3/download.asp
这是关于城市的
ISO 3166 https://en.wikipedia.org/wiki/ISO_3166-1

城市与语言 都从以前的2个英文字母改成了3个,并添加不少新的城市与语言进去

关于解释tts个人感觉不错的网址
https://www.programcreek.com/java-api-examples/index.php?api=android.speech.tts.TextToSpeech.OnInitListener

https://developer.android.com/reference/android/speech/tts/TextToSpeech.html


package com.linyb.tts;

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 {
    Button speak;
    EditText text;
    TextToSpeech speaker;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        speak = (Button) findViewById(R.id.button);
        text = (EditText) findViewById(R.id.edittext);

        speak.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                speaker = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {


                    public void onInit(int arg0) {
                        // TODO Auto-generated method stub

                        Log.d("tts", "使用的tts安装包: "+speaker.getDefaultEngine());
                        //使用粤语
                        Locale locale = new Locale("yue","HKG");
                        //speaker.setLanguage(Locale.TRADITIONAL_CHINESE);
                        speaker.setLanguage(locale);
                        speaker.speak(text.getText().toString(), TextToSpeech.QUEUE_FLUSH, null);
                    }
                });
            }
        });
    }
}

你可能感兴趣的:(安卓)