谷歌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);
                    }
                });
            }
        });
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值