<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                安卓上面語音識別和聊天機器人是非常常見也是非常實用的功能,在這里主要分享一款非常著名的語言平臺,[科大迅飛開放平臺](http://www.xfyun.cn/)。 首先從官網下載一個sdk的包,如下圖: ![](https://box.kancloud.cn/2016-03-14_56e65d6b687bb.jpg) 我們可以新建一個安卓工程,取名Robot,將下載下來的文件中的libs中的文件拷貝到我們的項目中的libs目錄下,然后寫一下布局文件: activity_main.xml ~~~ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/lv_list" android:layout_width="wrap_content" android:layout_height="0dp" android:divider="@null" android:layout_weight="1" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/bottom_bar" android:gravity="center" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="10dp" android:background="@drawable/btn_selector" android:onClick="startListen" android:text="點擊開始語音識別" android:textColor="#000" android:textSize="16sp" /> </LinearLayout> </LinearLayout> ~~~ list_item.xml ~~~ <?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" > <TextView android:id="@+id/tv_ask" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_margin="5dp" android:background="@drawable/asker_bubble" android:gravity="center" android:text="你吃飯了嗎?" android:textColor="#000" android:textSize="16sp" /> <LinearLayout android:id="@+id/ll_answer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/tv_ask" android:layout_margin="5dp" android:background="@drawable/answer_bubble" android:orientation="vertical" > <TextView android:id="@+id/tv_answer" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="" android:textColor="#000" android:textSize="16sp" /> <ImageView android:id="@+id/iv_pic" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/m" android:visibility="gone" /> </LinearLayout> </RelativeLayout> ~~~ 界面效果如下: ![](https://box.kancloud.cn/2016-03-14_56e65d6b98895.jpg) 我們可以在主界面中實現上面的功能: // 初始化語音引擎 SpeechUtility.createUtility(this, SpeechConstant.APPID + "=54b8bca3"); ~~~ /** * 語音朗誦 */ public void read(String text) { SpeechSynthesizer mTts = SpeechSynthesizer .createSynthesizer(this, null); mTts.setParameter(SpeechConstant.VOICE_NAME, "xiaoyan"); mTts.setParameter(SpeechConstant.SPEED, "50"); mTts.setParameter(SpeechConstant.VOLUME, "80"); mTts.setParameter(SpeechConstant.ENGINE_TYPE, SpeechConstant.TYPE_CLOUD); mTts.startSpeaking(text, null); } /** * 開始語音識別 * * @param view */ public void startListen(View view) { RecognizerDialog iatDialog = new RecognizerDialog(this, null); // 2.設置聽寫參數,詳見《科大訊飛MSC API手冊(Android)》SpeechConstant類 iatDialog.setParameter(SpeechConstant.DOMAIN, "iat"); iatDialog.setParameter(SpeechConstant.LANGUAGE, "zh_cn"); iatDialog.setParameter(SpeechConstant.ACCENT, "mandarin"); iatDialog.setListener(recognizerDialogListener); iatDialog.show(); } class ChatAdapter extends BaseAdapter { @Override public int getCount() { return mChatList.size(); } @Override public ChatBean getItem(int position) { return mChatList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder; if (convertView == null) { holder = new ViewHolder(); convertView = View.inflate(MainActivity.this, R.layout.list_item, null); holder.tvAsk = (TextView) convertView.findViewById(R.id.tv_ask); holder.tvAnswer = (TextView) convertView .findViewById(R.id.tv_answer); holder.llAnswer = (LinearLayout) convertView .findViewById(R.id.ll_answer); holder.ivPic = (ImageView) convertView .findViewById(R.id.iv_pic); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } ChatBean item = getItem(position); if (item.isAsker) {// 是提問者 holder.tvAsk.setVisibility(View.VISIBLE); holder.llAnswer.setVisibility(View.GONE); holder.tvAsk.setText(item.text); } else { holder.tvAsk.setVisibility(View.GONE); holder.llAnswer.setVisibility(View.VISIBLE); holder.tvAnswer.setText(item.text); if (item.imageId != -1) {// 有圖片 holder.ivPic.setVisibility(View.VISIBLE); holder.ivPic.setImageResource(item.imageId); } else { holder.ivPic.setVisibility(View.GONE); } } return convertView; } } static class ViewHolder { public TextView tvAsk; public TextView tvAnswer; public LinearLayout llAnswer; public ImageView ivPic; } /** * 解析語音數據 * * @param resultString */ protected String parseData(String resultString) { Gson gson = new Gson(); VoiceBean bean = gson.fromJson(resultString, VoiceBean.class); ArrayList<WSBean> ws = bean.ws; StringBuffer sb = new StringBuffer(); for (WSBean wsBean : ws) { String text = wsBean.cw.get(0).w; sb.append(text); } return sb.toString(); } ~~~ 當啟動的時候是這樣的![](https://box.kancloud.cn/2016-03-14_56e65d6be8f4e.jpg) 更多的功能我們可以去看開發者文檔。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看