android菜鸟开发遇到的小问题
来源:互联网 发布:希捷硬盘数据恢复软件 编辑:程序博客网 时间:2024/04/20 12:48
今天在设置一个单词阅读器,可是在手机上不能发出声音,而在模拟器上可以发出声音,求解。
代码:
package com.example.tts;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Speech extends Activity {
TextToSpeech tts;
EditText editText;
Button speech;
Button 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.US);
System.out.println("result=" + result);
System.out.println("TextToSpeech.LANG_COUNTRY_AVAILABLE=" + TextToSpeech.LANG_COUNTRY_AVAILABLE);
System.out.println("TextToSpeech.LANG_AVAILABLE=" + TextToSpeech.LANG_AVAILABLE);
if (result != TextToSpeech.LANG_COUNTRY_AVAILABLE
&& result != TextToSpeech.LANG_AVAILABLE){
Toast.makeText(Speech.this, "TTS暂不支持这种语言的朗读", Toast.LENGTH_LONG).show();
}
}
}
});
editText = (EditText)findViewById(R.id.txt);
speech = (Button)findViewById(R.id.speech);
record = (Button)findViewById(R.id.record);
speech.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tts.speak(editText.getText().toString(), TextToSpeech.QUEUE_ADD, null);
}
});
record.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tts.synthesizeToFile(editText.getText().toString(), null, "/mnt/sdcard/sound.wav");
Toast.makeText(Speech.this, "声音记录成功!", Toast.LENGTH_LONG).show();
}
});
}
@Override
public void 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;
}
}
在手机上会出现红色字体部分,而在模拟器上运行会,可以发出声音。
- android菜鸟开发遇到的小问题
- 菜鸟Android开发起步遇到的小问题————OKHttp回调时请求后出现的问题
- Android开发遇到的小问题
- android开发遇到的小问题备忘
- android开发遇到的一个小问题
- Android开发中遇到的小问题
- android开发遇到的小问题
- 小菜鸟遇到的问题1
- android开发菜鸟遇到的炕
- 用Eclipse开发Android时遇到的一个小问题
- Eclipse 开发Android小程序遇到的问题总结
- Android开发过程中遇到的一些小问题
- android 开发中遇到的一个小问题
- android开发过程中遇到的小问题
- android开发过程中遇到的小问题
- 学习android开发中遇到的一些小问题
- Eclipse 开发Android小程序遇到的问题总结
- 初涉Android开发遇到的一些新手小问题
- loadrunner走socket协议写发送数据脚本
- 选择问题的算法
- listfragment onlistitemclick 没有响应 没有调用
- SSH不能连接并提示REMOTE HOST IDENTIFICATION HAS CHANGED解决
- dos 批处理
- android菜鸟开发遇到的小问题
- 25年后的统计系会是什么样?
- 12045徐波:PMBOK融会贯通:几种估算类比:类比估算、参数估算、自下而上估算、三点估算
- CSS学习笔记-学习CSS布局
- 第十一周
- 多媒体ASF WMV AVI
- 在windows里查看oracle进程线程信息
- fatal error RC1015: cannot open include file 'resource.h'.
- Follow your heart, always remember who you are, what you want to be.