zoukankan      html  css  js  c++  java
  • 自动朗读 TTS

    public class MainActivity extends Activity {

        TextToSpeech tts;
        EditText say;
        Button speech,record;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            tts=new TextToSpeech(this, new OnInitListener() {
                
                @Override
                public void onInit(int status) {
                    if(status==TextToSpeech.SUCCESS)
                    {
                        int result=tts.setLanguage(Locale.getDefault());
                        if(result!=TextToSpeech.LANG_COUNTRY_AVAILABLE&&result!=TextToSpeech.LANG_AVAILABLE)
                        {
                            Toast.makeText(MainActivity.this, "TTS暂时不支持这种语言的朗读", Toast.LENGTH_SHORT).show();
                        }
                    }
                }
            });
            findid();
        }

        private void findid() {
            // TODO Auto-generated method stub
            say=(EditText) findViewById(R.id.say);
            speech=(Button) findViewById(R.id.speech);
            record=(Button) findViewById(R.id.record);
            speech.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    tts.speak(say.getText().toString(), TextToSpeech.QUEUE_ADD, null);
                }
            });
            record.setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    tts.synthesizeToFile(say.getText().toString(), null, "/mnt/sdcard/sound.wav");
                    Toast.makeText(MainActivity.this, "声音记录成功!", Toast.LENGTH_SHORT).show();
                }
            });
        }
        
        @Override
        protected void onDestroy() {
            // TODO Auto-generated method stub
            super.onDestroy();
            if(tts!=null)
            {
                tts.shutdown();
            }
        }

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }

    }

  • 相关阅读:
    NGINX_深度优化实践
    NFS服务端___NFS客户端
    NFS 批量管理 分发
    MYSQL---数据备份与还原
    MYSQL---建立字符集数据库
    MYSQL---基于mysql多实例数据库创建主从复制
    MYSQL---关于MYSQL优化
    bug记录-left jion连接后不是一对一情况时,记得去重
    bug记录-不等于某个值,查询后注意不包括为空的情况(由于NULL不能直接用算术运算符进行比较值。要想把为NULL 的那行也查询出来的话,只能使用IS NULL)
    bug记录-sqljion连接 like
  • 原文地址:https://www.cnblogs.com/lk119/p/3349372.html
Copyright © 2011-2022 走看看