如何实现讯飞语音录入和输出与图灵机器人结合
来源:互联网 发布:cms建站系统 java 编辑:程序博客网 时间:2024/04/29 21:01
我这里直接在图灵机器人实现人与机器人俩天的基础上,调用了讯飞的几个方法在来实现语音的录入与输出,很简单大家可以参考学习
这是对话框
这是右边
package com.lcmf.robot;import java.util.ArrayList;import java.util.Date;import java.util.HashMap;import java.util.LinkedHashMap;import java.util.List;import android.annotation.SuppressLint;import android.app.Activity;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.content.SharedPreferences;import android.os.Bundle;import android.os.Environment;import android.os.Handler;import android.os.Message;import android.text.TextUtils;import android.util.Log;import android.view.KeyEvent;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.View.OnClickListener;import android.view.Window;import android.view.inputmethod.InputMethodManager;import android.widget.EditText;import android.widget.ListView;import android.widget.RadioGroup;import android.widget.Toast;import com.iflytek.cloud.ErrorCode;import com.iflytek.cloud.InitListener;import com.iflytek.cloud.RecognizerListener;import com.iflytek.cloud.RecognizerResult;import com.iflytek.cloud.SpeechConstant;import com.iflytek.cloud.SpeechError;import com.iflytek.cloud.SpeechRecognizer;import com.iflytek.cloud.SpeechSynthesizer;import com.iflytek.cloud.SynthesizerListener;import com.iflytek.cloud.ui.RecognizerDialog;import com.iflytek.cloud.ui.RecognizerDialogListener;import com.iflytek.cloud.util.ResourceUtil;import com.iflytek.cloud.util.ResourceUtil.RESOURCE_TYPE;import com.iflytek.speech.setting.IatSettings;import com.iflytek.speech.setting.TtsSettings;import com.iflytek.speech.util.JsonParser;import com.lcmf.ad.QuitPopAd;import com.lcmf.ad.SlideWall;import com.lcmf.menu.MainClass;import com.lcmf.robot.bean.ChatMessage;import com.lcmf.robot.bean.ChatMessage.Type;import com.lcmf.tts.TtsDemo;import com.zhy.utils.HttpUtils;//import android.speech.SpeechRecognizer;public class MainActivity extends Activity implements OnClickListener {private static String TAG = MainActivity.class.getSimpleName(); // 语音合成对象private SpeechSynthesizer mTts;/** * 展示消息的listview */// 听写结果内容private ListView mChatView;// 语音听写对象private SpeechRecognizer mIat;/** * 文本域 */private SharedPreferences mSharedPreferences;private RecognizerDialog mIatDialog;private EditText mMsg;private EditText mGetMsg;/** * 存储聊天消息 */// 默认云端发音人public static String voicerCloud="xiaoyan";// 默认本地发音人public static String voicerLocal="xiaoyan";// 云端发音人列表private String[] cloudVoicersEntries;private String[] cloudVoicersValue ;// 本地发音人列表private String[] localVoicersEntries;private String[] localVoicersValue ;private HashMap<String, String> mIatResults = new LinkedHashMap<String, String>();//缓冲进度private int mPercentForBuffering = 0;//播放进度private int mPercentForPlaying = 0;// 云端/本地选择按钮private RadioGroup mRadioGroup;// 引擎类型private String mEngineType = SpeechConstant.TYPE_CLOUD;private Toast mToast;@SuppressLint("ShowToast")private List<ChatMessage> mDatas = new ArrayList<ChatMessage>();/** * 适配器 */private ChatMessageAdapter mAdapter;private Handler mHandler = new Handler() {public void handleMessage(android.os.Message msg) { ChatMessage from = (ChatMessage) msg.obj;mDatas.add(from);mAdapter.notifyDataSetChanged();mChatView.setSelection(mDatas.size() - 1);mGetMsg.setText(from.getMsg().toString());};};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.main_chatting);initView();// 使用SpeechRecognizer对象,可根据回调消息自定义界面;mIat = SpeechRecognizer.createRecognizer(this, mInitListener);// 初始化听写Dialog,如果只使用有UI听写功能,无需创建SpeechRecognizer// 使用UI听写功能,请根据sdk文件目录下的notice.txt,放置布局文件和图片资源mIatDialog = new RecognizerDialog(this, mInitListener);mAdapter = new ChatMessageAdapter(this, mDatas);mChatView.setAdapter(mAdapter);// 初始化合成对象mTts = SpeechSynthesizer.createSynthesizer(this, mTtsInitListener);// 云端发音人名称列表cloudVoicersEntries = getResources().getStringArray(R.array.voicer_cloud_entries);cloudVoicersValue = getResources().getStringArray(R.array.voicer_cloud_values);// 本地发音人名称列表localVoicersEntries = getResources().getStringArray(R.array.voicer_local_entries);localVoicersValue = getResources().getStringArray(R.array.voicer_local_values);mSharedPreferences = getSharedPreferences(TtsSettings.PREFER_NAME, Activity.MODE_PRIVATE);mToast = Toast.makeText(this,"",Toast.LENGTH_SHORT);//SpeechRecognizer mIat = SpeechRecognizer.createSpeechRecognizer(this,null); // mIat.setParameter(SpeechConstant.DOMAIN,"iat"); // mIat.setParameter(SpeechConstant.LANGUAGE,"zh_cn");} @Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);menu.add(Menu.NONE, Menu.FIRST + 1, 5, "语音设置").setIcon(android.R.drawable.ic_menu_delete);menu.add(Menu.NONE, Menu.FIRST + 2, 2, "听写设置").setIcon(android.R.drawable.ic_menu_edit);menu.add(Menu.NONE, Menu.FIRST + 3, 6, "选择发音人").setIcon(android.R.drawable.ic_menu_help);/*menu.add(Menu.NONE, Menu.FIRST + 4, 1, "添加").setIcon(android.R.drawable.ic_menu_add);menu.add(Menu.NONE, Menu.FIRST + 5, 4, "详细").setIcon(android.R.drawable.ic_menu_info_details);menu.add(Menu.NONE, Menu.FIRST + 6, 3, "发送").setIcon(android.R.drawable.ic_menu_send);*/return true;} @Overridepublic boolean onOptionsItemSelected(MenuItem item) {switch (item.getItemId()) {case Menu.FIRST + 1:Toast.makeText(this, "语音设置", Toast.LENGTH_LONG).show();Intent intent = new Intent(MainActivity.this,TtsSettings.class);startActivity(intent);break;case Menu.FIRST + 2:Toast.makeText(this, "听写设置", Toast.LENGTH_LONG).show();Intent intent1 = new Intent(MainActivity.this, IatSettings.class);startActivity(intent1);break;case Menu.FIRST + 3:Toast.makeText(this, "选择发音人", Toast.LENGTH_LONG).show();showPresonSelectDialog();break;}return false;}@Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {if (keyCode == KeyEvent.KEYCODE_BACK) {if (SlideWall.getInstance().slideWallDrawer != null && SlideWall.getInstance().slideWallDrawer.isOpened()) {// 如果抽屉式应用墙展示中,则关闭抽屉SlideWall.getInstance().closeSlidingDrawer();} else {// 调用退屏广告QuitPopAd.getInstance().show(this);}}return true;}private void initView() {mChatView = (ListView) findViewById(R.id.id_chat_listView);mMsg = (EditText) findViewById(R.id.id_chat_msg);mGetMsg = (EditText) findViewById(R.id.id_get_msg);mDatas.add(new ChatMessage(Type.INPUT, "你好,我是小智机器人"));}int ret = 0;// 函数调用返回值 public void menu(View view){ Intent intent = new Intent(MainActivity.this,MainClass.class); startActivity(intent); }public void sendMessage(View view) {final String msg = mMsg.getText().toString();if (TextUtils.isEmpty(msg)) {Toast.makeText(this, "您还没有填写消息呢吧...", Toast.LENGTH_SHORT).show();return;}ChatMessage to = new ChatMessage(Type.OUTPUT, msg);to.setDate(new Date());mDatas.add(to);mAdapter.notifyDataSetChanged();mChatView.setSelection(mDatas.size() - 1);mMsg.setText("");// 关闭软键盘InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);// 得到InputMethodManager的实例if (imm.isActive()) {// 如果开启imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT,InputMethodManager.HIDE_NOT_ALWAYS);// 关闭软键盘,开启方法相同,这个方法是切换开启与关闭状态的}new Thread() {public void run() {ChatMessage from = null;try {from = HttpUtils.sendMsg(msg);} catch (Exception e) {from = new ChatMessage(Type.INPUT, "服务器连接失败...");}Message message = Message.obtain();message.obj = from;mHandler.sendMessage(message);};}.start();}/** * 语音转文字 * @param v */public void getVoice(View v){ // SpeechRecognizer mIat = SpeechRecognizer.createSpeechRecognizer(context.null); // mIat.setParameter(SpeechConstant.DOMAIN,"iat"); // mIat.setParameter(SpeechConstant.LANGUAGE,"zh_cn");mMsg.setText(null);// 清空显示内容mIatResults.clear();// 设置参数setParam1();boolean isShowDialog = mSharedPreferences.getBoolean(getString(R.string.pref_key_iat_show), true);if (isShowDialog) {// 显示听写对话框mIatDialog.setListener(mRecognizerDialogListener);mIatDialog.show();showTip(getString(R.string.text_begin));} else {// 不显示听写对话框ret = mIat.startListening(mRecognizerListener);if (ret != ErrorCode.SUCCESS) {showTip("听写失败,错误码:" + ret);} else {showTip(getString(R.string.text_begin));}}}/** * 参数设置 * @param param * @return */public void setParam1() {// 清空参数mIat.setParameter(SpeechConstant.PARAMS, null);String lag = mSharedPreferences.getString("iat_language_preference","mandarin");// 设置引擎mIat.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);// 设置返回结果格式mIat.setParameter(SpeechConstant.RESULT_TYPE, "json");if (lag.equals("en_us")) {// 设置语言mIat.setParameter(SpeechConstant.LANGUAGE, "en_us");} else {// 设置语言mIat.setParameter(SpeechConstant.LANGUAGE, "zh_cn");// 设置语言区域mIat.setParameter(SpeechConstant.ACCENT, lag);}// 设置语音前端点:静音超时时间,即用户多长时间不说话则当做超时处理mIat.setParameter(SpeechConstant.VAD_BOS,mSharedPreferences.getString("iat_vadbos_preference", "4000"));// 设置语音后端点:后端点静音检测时间,即用户停止说话多长时间内即认为不再输入, 自动停止录音mIat.setParameter(SpeechConstant.VAD_EOS,mSharedPreferences.getString("iat_vadeos_preference", "1000"));// 设置标点符号,设置为"0"返回结果无标点,设置为"1"返回结果有标点mIat.setParameter(SpeechConstant.ASR_PTT,mSharedPreferences.getString("iat_punc_preference", "1"));// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限// 注:AUDIO_FORMAT参数语记需要更新版本才能生效mIat.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");mIat.setParameter(SpeechConstant.ASR_AUDIO_PATH,Environment.getExternalStorageDirectory() + "/msc/iat.wav");}/** * 初始化监听器。 */private InitListener mInitListener = new InitListener() {@Overridepublic void onInit(int code) {Log.d(TAG, "SpeechRecognizer init() code = " + code);if (code != ErrorCode.SUCCESS) {showTip("初始化失败,错误码:" + code);}}};/** * 听写监听器。 */private RecognizerListener mRecognizerListener = new RecognizerListener() {@Overridepublic void onBeginOfSpeech() {// 此回调表示:sdk内部录音机已经准备好了,用户可以开始语音输入showTip("开始说话");}@Overridepublic void onError(SpeechError error) {// Tips:// 错误码:10118(您没有说话),可能是录音机权限被禁,需要提示用户打开应用的录音权限。showTip(error.getPlainDescription(true));}@Overridepublic void onEndOfSpeech() {// 此回调表示:检测到了语音的尾端点,已经进入识别过程,不再接受语音输入showTip("结束说话");}@Overridepublic void onResult(RecognizerResult results, boolean isLast) {String text = JsonParser.parseIatResult(results.getResultString());mMsg.append(text);mMsg.setSelection(mMsg.length());if (isLast) {// TODO 最后的结果}}@Overridepublic void onVolumeChanged(int volume, byte[] data) {showTip("当前正在说话,音量大小:" + volume);Log.d(TAG, "返回音频数据:" + data.length);}@Overridepublic void onEvent(int eventType, int arg1, int arg2, Bundle obj) {// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因// 若使用本地能力,会话id为null// if (SpeechEvent.EVENT_SESSION_ID == eventType) {// String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);// Log.d(TAG, "session id =" + sid);// }}};/** * 听写UI监听器 */private RecognizerDialogListener mRecognizerDialogListener = new RecognizerDialogListener() {public void onResult(RecognizerResult results, boolean isLast) {Log.d(TAG, "recognizer result:" + results.getResultString());String text = JsonParser.parseIatResult(results.getResultString());mMsg.append(text);mMsg.setSelection(mMsg.length());}/** * 识别回调错误. */public void onError(SpeechError error) {showTip(error.getPlainDescription(true));}}; private RecognizerListener mRecoListener = new RecognizerListener() {@Overridepublic void onVolumeChanged(int volume, byte[] arg1) {// TODO Auto-generated method stub }@Overridepublic void onResult(RecognizerResult results, boolean isLast) {// TODO Auto-generated method stubLog.d("Result:", results.getResultString());}@Overridepublic void onEvent(int eventType, int arg1, int arg2, Bundle obj) {// TODO Auto-generated method stub}@Overridepublic void onError(SpeechError error) {// TODO Auto-generated method stuberror.getPlainDescription(true);}@Overridepublic void onEndOfSpeech() {// TODO Auto-generated method stub}@Overridepublic void onBeginOfSpeech() {// TODO Auto-generated method stub} }; //释放语音 public void getMessage(View view){ String text = mGetMsg.getText().toString();// 设置参数setParam();int code = mTts.startSpeaking(text, mTtsListener);if (code != ErrorCode.SUCCESS) {Toast.makeText(MainActivity.this, "语音合成失败,错误码: "+code, 5000).show();} } /** * 初始化监听。 */private InitListener mTtsInitListener = new InitListener() {@Overridepublic void onInit(int code) {Log.d(TAG, "InitListener init() code = " + code);if (code != ErrorCode.SUCCESS) { showTip("初始化失败,错误码:"+code); } else {// 初始化成功,之后可以调用startSpeaking方法 // 注:有的开发者在onCreate方法中创建完合成对象之后马上就调用startSpeaking进行合成, // 正确的做法是将onCreate中的startSpeaking调用移至这里}}};/** * 合成回调监听。 */private SynthesizerListener mTtsListener = new SynthesizerListener() {@Overridepublic void onSpeakBegin() {showTip("开始播放");}@Overridepublic void onSpeakPaused() {showTip("暂停播放");}@Overridepublic void onSpeakResumed() {showTip("继续播放");}@Overridepublic void onBufferProgress(int percent, int beginPos, int endPos,String info) {// 合成进度mPercentForBuffering = percent;showTip(String.format(getString(R.string.tts_toast_format),mPercentForBuffering, mPercentForPlaying));}@Overridepublic void onSpeakProgress(int percent, int beginPos, int endPos) {// 播放进度mPercentForPlaying = percent;showTip(String.format(getString(R.string.tts_toast_format),mPercentForBuffering, mPercentForPlaying));}@Overridepublic void onCompleted(SpeechError error) {if (error == null) {showTip("播放完成");} else if (error != null) {showTip(error.getPlainDescription(true));}}@Overridepublic void onEvent(int eventType, int arg1, int arg2, Bundle obj) {// 以下代码用于获取与云端的会话id,当业务出错时将会话id提供给技术支持人员,可用于查询会话日志,定位出错原因// 若使用本地能力,会话id为null//if (SpeechEvent.EVENT_SESSION_ID == eventType) {//String sid = obj.getString(SpeechEvent.KEY_EVENT_SESSION_ID);//Log.d(TAG, "session id =" + sid);//}}};private void showTip(final String str){runOnUiThread(new Runnable() {@Overridepublic void run() {mToast.setText(str);mToast.show();}});}private void setParam(){// 清空参数mTts.setParameter(SpeechConstant.PARAMS, null);//设置合成if(mEngineType.equals(SpeechConstant.TYPE_CLOUD)){//设置使用云端引擎mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD);//设置发音人mTts.setParameter(SpeechConstant.VOICE_NAME,voicerCloud);}else {//设置使用本地引擎mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_LOCAL);//设置发音人资源路径mTts.setParameter(ResourceUtil.TTS_RES_PATH,getResourcePath());//设置发音人mTts.setParameter(SpeechConstant.VOICE_NAME,voicerLocal);}//设置合成语速mTts.setParameter(SpeechConstant.SPEED, mSharedPreferences.getString("speed_preference", "500"));//设置合成音调mTts.setParameter(SpeechConstant.PITCH, mSharedPreferences.getString("pitch_preference", "500"));//设置合成音量mTts.setParameter(SpeechConstant.VOLUME, mSharedPreferences.getString("volume_preference", "500"));//设置播放器音频流类型mTts.setParameter(SpeechConstant.STREAM_TYPE, mSharedPreferences.getString("stream_preference", "3"));// 设置播放合成音频打断音乐播放,默认为truemTts.setParameter(SpeechConstant.KEY_REQUEST_FOCUS, "true");// 设置音频保存路径,保存音频格式支持pcm、wav,设置路径为sd卡请注意WRITE_EXTERNAL_STORAGE权限// 注:AUDIO_FORMAT参数语记需要更新版本才能生效mTts.setParameter(SpeechConstant.AUDIO_FORMAT, "wav");mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/tts.wav");}//获取发音人资源路径private String getResourcePath(){StringBuffer tempBuffer = new StringBuffer();//合成通用资源tempBuffer.append(ResourceUtil.generateResourcePath(this, RESOURCE_TYPE.assets, "tts/common.jet"));tempBuffer.append(";");//发音人资源tempBuffer.append(ResourceUtil.generateResourcePath(this, RESOURCE_TYPE.assets, "tts/"+TtsDemo.voicerLocal+".jet"));return tempBuffer.toString();}@Overridepublic void onClick(View v) {// TODO Auto-generated method stub}private static int selectedNumCloud=0;private static int selectedNumLocal=0;/** * 发音人选择。 */private void showPresonSelectDialog() {switch (1) {// 选择在线合成case 1:new AlertDialog.Builder(this).setTitle("在线合成发音人选项").setSingleChoiceItems(cloudVoicersEntries, // 单选框有几项,各是什么名字selectedNumCloud, // 默认的选项new DialogInterface.OnClickListener() { // 点击单选框后的处理public void onClick(DialogInterface dialog,int which) { // 点击了哪一项voicerCloud = cloudVoicersValue[which];/*if ("catherine".equals(voicerCloud) || "henry".equals(voicerCloud) || "vimary".equals(voicerCloud)) { ((EditText) findViewById(R.id.id_get_msg)).setText(R.string.text_tts_source_en);}else {((EditText) findViewById(R.id.id_get_msg)).setText(R.string.text_tts_source);}*/selectedNumCloud = which;dialog.dismiss();}}).show();break;// 选择本地合成//case R.id.tts_radioLocal://new AlertDialog.Builder(this).setTitle("本地合成发音人选项")//.setSingleChoiceItems(localVoicersEntries, // 单选框有几项,各是什么名字//selectedNumLocal, // 默认的选项//new DialogInterface.OnClickListener() { // 点击单选框后的处理//public void onClick(DialogInterface dialog,//int which) { // 点击了哪一项//voicerLocal = localVoicersValue[which];//if ("catherine".equals(voicerLocal) || "henry".equals(voicerLocal) || "vimary".equals(voicerLocal)) {// ((EditText) findViewById(R.id.id_get_msg)).setText(R.string.text_tts_source_en);//}else {//((EditText) findViewById(R.id.id_get_msg)).setText(R.string.text_tts_source);//}//selectedNumLocal = which;//dialog.dismiss();//}//}).show();//break;default:break;}}}
下面是适配器很简单,可以参考
package com.lcmf.robot;import java.util.List;import android.content.Context;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.TextView;import com.lcmf.robot.R;import com.lcmf.robot.bean.ChatMessage;import com.lcmf.robot.bean.ChatMessage.Type;public class ChatMessageAdapter extends BaseAdapter {private LayoutInflater mInflater;private List<ChatMessage> mDatas;public ChatMessageAdapter(Context context, List<ChatMessage> datas) {mInflater = LayoutInflater.from(context);mDatas = datas;}@Overridepublic int getCount() {return mDatas.size();}@Overridepublic Object getItem(int position) {return mDatas.get(position);}@Overridepublic long getItemId(int position) {return position;}/** * 接受到消息为1,发送消息为0 */@Overridepublic int getItemViewType(int position) {ChatMessage msg = mDatas.get(position);return msg.getType() == Type.INPUT ? 1 : 0;}@Overridepublic int getViewTypeCount() {return 2;}@Overridepublic View getView(int position, View convertView, ViewGroup parent) {ChatMessage chatMessage = mDatas.get(position);ViewHolder viewHolder = null;if (convertView == null) {viewHolder = new ViewHolder();if (chatMessage.getType() == Type.INPUT) {convertView = mInflater.inflate(R.layout.main_chat_from_msg,parent, false);viewHolder.createDate = (TextView) convertView.findViewById(R.id.chat_from_createDate);viewHolder.content = (TextView) convertView.findViewById(R.id.chat_from_content);convertView.setTag(viewHolder);} else {convertView = mInflater.inflate(R.layout.main_chat_send_msg,null);viewHolder.createDate = (TextView) convertView.findViewById(R.id.chat_send_createDate);viewHolder.content = (TextView) convertView.findViewById(R.id.chat_send_content);convertView.setTag(viewHolder);}} else {viewHolder = (ViewHolder) convertView.getTag();}viewHolder.content.setText(chatMessage.getMsg());viewHolder.createDate.setText(chatMessage.getDateStr());return convertView;}private class ViewHolder {public TextView createDate;public TextView name;public TextView content;}}布局文件如下,我不怎么会写文章,你们直接看代码吧
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#2ea3fe" android:orientation="vertical" > <RelativeLayout android:id="@+id/ly_chat_title" android:layout_width="fill_parent" android:layout_height="45dp" android:background="@drawable/title_bar" > <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="小智" android:textColor="#fff" android:textSize="20sp" android:textStyle="bold" /> <!-- android:visibility="invisible" --> <Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:background="@drawable/home" android:onClick="menu" /> <!-- <Button android:id="@+id/button3" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/button2" android:onClick="getMessage" android:text="读取小熊" /> --> <ImageButton android:id="@+id/imageButton2" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentTop="true" android:layout_marginLeft="26dp" android:layout_toRightOf="@+id/button2" android:onClick="getMessage" android:src="@drawable/sound" /> <ImageButton android:id="@+id/imageButton1" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="65dp" android:onClick="getVoice" android:src="@drawable/com" /> </RelativeLayout> <RelativeLayout android:id="@+id/ly_chat_bottom" android:layout_width="fill_parent" android:layout_height="55dp" android:layout_alignParentBottom="true" android:background="@drawable/bottom_bar" > <Button android:id="@+id/id_chat_send" android:layout_width="60dp" android:layout_height="40dp" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:background="@drawable/chat_send_btn" android:onClick="sendMessage" android:text="发送" /> <EditText android:id="@+id/id_chat_msg" android:layout_width="130dp" android:layout_height="40dp" android:layout_alignBaseline="@+id/id_chat_send" android:layout_alignBottom="@+id/id_chat_send" android:layout_marginRight="0dp" android:layout_toLeftOf="@+id/id_chat_send" android:layout_toRightOf="@+id/id_get_msg" android:background="@drawable/login_edit_normal" android:ems="10" android:singleLine="true" android:textSize="18sp" > <requestFocus /> </EditText><!-- <ImageButton android:id="@+id/bt_search" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignParentLeft="true" android:layout_alignTop="@+id/id_chat_msg" android:layout_marginLeft="0dp" android:onClick="btn" android:src="@drawable/sound1" /> --> <EditText android:id="@+id/id_get_msg" android:layout_width="40dp" android:layout_height="40dp" android:layout_marginLeft="0dp" android:background="@drawable/login_edit_normal" android:visibility="invisible" android:ems="10" android:textSize="18sp" /><!-- <Button android:id="@+id/person_set" style="?android:attr/buttonStyleSmall" android:layout_width="40dp" android:layout_height="40dp" android:layout_alignTop="@+id/id_get_msg" android:layout_toRightOf="@+id/id_get_msg" android:text="选择发音人" /> --> </RelativeLayout> <ListView android:id="@+id/id_chat_listView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_above="@id/ly_chat_bottom" android:layout_below="@id/ly_chat_title" android:cacheColorHint="#0000" android:divider="@null" android:dividerHeight="5dp" android:scrollbarStyle="outsideOverlay" > </ListView><!-- <Button android:id="@+id/button4" style="?android:attr/buttonStyleSmall" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginRight="50dp" android:onClick="getVoice" android:text="读取音频" /> --></RelativeLayout>
这是对话框
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/chat_from_createDate" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2012-09-01 18:30:20" style="@style/chat_date_style" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:orientation="vertical" > <ImageView android:id="@+id/chat_from_icon" android:layout_width="49dp" android:layout_height="49dp" android:src="@drawable/text_bg" /> <TextView android:id="@+id/chat_from_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="lcrobot" android:textSize="18sp" /> </LinearLayout> <TextView android:id="@+id/chat_from_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="50dp" android:background="@drawable/chat_from_msg" android:text="lcmf。。。" android:textSize="18sp" android:textColor="#000" android:gravity="center_vertical" android:focusable="true" android:clickable="true" android:lineSpacingExtra="2dp" /> </LinearLayout></LinearLayout>
这是右边
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <TextView android:id="@+id/chat_send_createDate" style="@style/chat_date_style" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2012-09-01 18:30:21" /> <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/ly_chat_icon" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_marginLeft="10dp" android:orientation="vertical" > <ImageView android:id="@+id/chat_send_icon" android:layout_width="49dp" android:layout_height="49dp" android:src="@drawable/smallred" /> <TextView android:id="@+id/chat_send_name" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="lc" android:textSize="18sp" /> </LinearLayout> <TextView android:id="@+id/chat_send_content" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/ly_chat_icon" android:background="@drawable/chat_send_msg" android:clickable="true" android:focusable="true" android:gravity="center_vertical" android:lineSpacingExtra="2dp" android:minHeight="50dp" android:text="有大吗。。。" android:textColor="#000" android:textSize="18sp" /> </RelativeLayout></LinearLayout>
源码我分享啦,集成了很多游戏,不知道你们看不看得懂,有点乱,我的每一部分都有一个包,每一个游戏都是独自的一个包
http://download.csdn.net/detail/xulilongailulu/9367474
0 0
- 如何实现讯飞语音录入和输出与图灵机器人结合
- 安卓——图灵机器人+讯飞语音设计实现
- 树莓派语音聊天机器人(基于讯飞语音和图灵机器人)
- 基于讯飞语音,百度语音,图灵机器人的智能语音机器人毕业设计第一天
- 安卓实现智能聊天机器人(结合百度语音和图灵机器人)
- Python结合图灵机器人
- 【ppt入门教程】如何让ppt与Excel工作表结合 实现数据的录入与计算
- Unity结合讯飞语音在线识别
- 如何集成图灵机器人,简单实现语音聊天
- 与图灵机器人聊天
- 用wxBot和图灵机器人API实现微信群聊机器人
- python实现和图灵机器人对话功能
- 基于讯飞语音,百度语音,图灵机器人树莓派的智能语音机器人毕业设计第二天
- 基于讯飞语音,百度语音,图灵机器人树莓派的智能语音机器人毕业设计第三天
- 基于讯飞语音,百度语音,图灵机器人树莓派的智能语音机器人毕业设计第四天
- 简单的例子:Java结合图灵机器人开发
- 简单的例子:Java结合图灵机器人开发
- Android图灵机器人的实现(一)
- handler使用
- 数据结构 二叉树的递归算法、前序、中序、后序遍历(c语言实现)
- 键盘问题导致BIOS自检失败
- HDU-1520 Anniversary party(树形DP)
- scala学习笔记3-Actor、case class和object、loop和react的使用
- 如何实现讯飞语音录入和输出与图灵机器人结合
- Qt之Tab键切换焦点顺序
- Apache HttpClient4.5(一)
- GNU内联汇编之占位符的使用
- c++动态创建二维数组
- HDOJ--2031
- 如何用js完美的解析lrc歌词
- bzoj3550【ONTAK2010】Vacation
- 黑马程序员--多态 内部类