语音识别,语义理解一站式解决(android平台olami sdk)
語(yǔ)音記賬demo:http://blog.csdn.net/ls0609/article/details/72765789
olami sdk實(shí)現(xiàn)了把錄音或者文字轉(zhuǎn)化為用戶可以理解的json字符串從而實(shí)現(xiàn)語(yǔ)義理解,用戶可以定義自己的語(yǔ)義,是不是很強(qiáng)大?本文講述怎么自定義語(yǔ)義,以及如何解析自定義語(yǔ)義。 本文使用olami sdk做了一個(gè)在線聽(tīng)書(shū)的demo,用戶只需類似“我想聽(tīng)***”就能實(shí)現(xiàn)聽(tīng)書(shū)的在線查找并播放。用的是喜馬拉雅的在線聽(tīng)書(shū)sdk.基于eclipse開(kāi)發(fā)環(huán)境,libs目錄下jar和so文件如下:olami-android-sdk.jar //olami sdk 的jar afinal_0.5.1_bin.jar litepal.jar gson-2.2.4.jar okhttp-2.4.0.jar okhttp-urlconnection-2.2.0.jar okio-1.4.0.jar opensdk.jar //上面這幾個(gè)都是喜馬拉雅需要的jar libspeex.so //olami sdk 需要用到speex壓縮功能 libxmediaplayer.so // 喜馬拉雅so libxmediaplayer_x.so // 喜馬拉雅so 概述:?
VoiceSdkService中定義了OlamiVoiceRecognizer語(yǔ)音識(shí)別引擎,通過(guò)點(diǎn)擊MusicActivity的開(kāi)始button啟動(dòng)錄音,錄音結(jié)果在VoiceSdkService中的onResult()回調(diào)中拿到識(shí)別的Json字符串,在processServiceMessage()函數(shù)中處理后找到要聽(tīng)書(shū)的名稱,然后進(jìn)入BookUtil進(jìn)行搜索,搜索到結(jié)果后通知VoiceSdkService進(jìn)行播放,并通知MusicActivity更新播放進(jìn)度等信息。
1.AndroidManifest.xml配置
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.olami.musicdemo"android:versionCode="1"android:versionName="1.0" ><uses-sdk android:minSdkVersion="8"android:targetSdkVersion="21" /><uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> <uses-permission android:name="android.permission.READ_PHONE_STATE"/><uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /><application android:name="com.olami.musicdemo.OlamiApplication"android:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" ><!--喜馬拉雅聽(tīng)書(shū)測(cè)試賬號(hào)app_key--><meta-data android:name="app_key"android:value="b617866c20482d133d5de66fceb37da3" /><!--喜馬拉雅聽(tīng)書(shū)測(cè)試賬號(hào)包名--><meta-data android:name="pack_id"android:value="com.app.test.android" /><activity android:name=".MusicActivity"android:label="@string/app_name" ><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><!--注冊(cè)olami sdk service--><service android:name=".VoiceSdkService"android:exported="true" ></service><!--注冊(cè)喜馬拉雅聽(tīng)書(shū)service--><service android:name="com.ximalaya.ting.android.opensdk.player.service.XmPlayerService"/></application></manifest>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
2.layout布局文件
layout_musicview.xml
TextView 有兩個(gè),tv_name顯示聽(tīng)書(shū)的名稱, tv_totoal_time顯示聽(tīng)書(shū)的總時(shí)間。?
ProgressBar 實(shí)時(shí)刷新顯示聽(tīng)書(shū)的進(jìn)度
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
activity_music.xml
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"tools:context="com.olami.musicdemo.MusicActivity" ><TextViewandroid:id="@+id/tv_inputText"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="5dp"android:text="輸入:" /><TextViewandroid:id="@+id/tv_volume"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/tv_inputText"android:layout_below="@+id/tv_inputText"android:layout_marginTop="40dp"android:text="音量:" /><TextViewandroid:id="@+id/tv_result"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/tv_volume"android:layout_marginTop="20dp"android:maxLines="15"android:ellipsize="end"android:text="服務(wù)器返回sentence:"android:visibility="visible" /><com.olami.musicdemo.MusicViewandroid:id="@+id/music_view"android:layout_width="fill_parent"android:layout_height="80dp"android:layout_centerInParent="true"></com.olami.musicdemo.MusicView><EditTextandroid:id="@+id/et_content"android:layout_width="wrap_content"android:layout_height="40dp"android:layout_above="@+id/btn_stop"android:layout_alignLeft="@+id/tv_inputText"android:layout_marginBottom="10dp"android:layout_toLeftOf="@+id/btn_send"android:background="#E7E7E7"android:singleLine="true"android:text="上海的天氣" /> <Buttonandroid:id="@+id/btn_send"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignBaseline="@+id/et_content"android:layout_alignBottom="@+id/et_content"android:layout_alignParentRight="true"android:text="提交" /><Buttonandroid:id="@+id/btn_start"android:layout_width="wrap_content"android:layout_height="wrap_content" android:layout_alignParentBottom="true"android:layout_centerHorizontal="true"android:text="開(kāi)始" /><Buttonandroid:id="@+id/btn_stop"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignLeft="@+id/et_content"android:layout_alignParentBottom="true"android:text="停止" /><Buttonandroid:id="@+id/btn_cancel"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_alignParentBottom="true"android:layout_toRightOf="@+id/et_content"android:text="取消" /></RelativeLayout>- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
自定義MusicView比較簡(jiǎn)單,代碼如下:
public class MusicView extends RelativeLayout{private Context mContext;private Handler mHandler;private TextView mTextViewName;private TextView mTextViewTotalTime;private ProgressBar mProgressBar;public MusicView(Context context,AttributeSet attrs) {super(context,attrs);LayoutInflater inflater =(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);RelativeLayout view = (RelativeLayout) inflater.inflate(R.layout.layout_musicview, this,true);mTextViewName = (TextView) view.findViewById(R.id.tv_name);mTextViewTotalTime = (TextView) view.findViewById(R.id.tv_total_time);mProgressBar = (ProgressBar)view.findViewById(R.id.progressbar_music);}public void initMusicView(Context context,Handler handler){mContext = context;mHandler = handler;}public void setMusicName(String name){//設(shè)置播放名稱mTextViewName.setText(name);}public void setProgress(int progress){//設(shè)置播放進(jìn)度mProgressBar.setProgress(progress);}public void setTotalTime(String time){//設(shè)置播放總時(shí)間mTextViewTotalTime.setText(time);}}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
布局效果圖如下:?
3.MusicActivity和VoiceSdkService通信
本文沒(méi)有用bind service的方式實(shí)現(xiàn)activity和service的消息通信。?
MusicAcitity 和 VoiceSdkService中分別實(shí)現(xiàn)了一個(gè)CommunicationAssist的接口
- 1
- 2
- 3
- 1
- 2
- 3
然后把他們分別實(shí)現(xiàn)CommunicationAssist接口的變量注冊(cè)到OlamiApplication,這樣通過(guò)OlamiApplication實(shí)現(xiàn)了MusicAcitity 和 VoiceSdkService橋接。
3.1OlamiApplication
1) 注冊(cè)MusicActivity到VoiceSdkService的回調(diào)
public void setActivityToServiceListener(CommunicationAssist listener) {ActivityToServiceListener = listener; }- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
這個(gè)是在VoiceSdkService中調(diào)用setActivityToServiceListener(),把VoiceSdkService中的VoiceSdkComAssist注冊(cè)到application中,MusicActivity中可以通過(guò)getActivityToServiceListener?
這個(gè)函數(shù)回調(diào)向VoiceSdkService發(fā)送消息。
2) 注冊(cè) VoiceSdkService到MusicActivity回調(diào)
public void setServiceToActivityListener(CommunicationAssist listener) {mServiceToActivityListener = listener; }- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
這個(gè)是在MusicAcitivity中調(diào)用setServiceToActivityListener(),這樣在VoiceSdkService中就可以通過(guò)getServiceToActivityListener()獲得回調(diào)向MusciActivity發(fā)送消息。
3.2 MusicActivity
public class MusicActivity extends Activity {private Handler mHandler;private Handler mInComingHandler;private ActivityComAssist mActivityComAssist;private Button mBtnStart;private Button mBtnStop;private Button mBtnCancel;private Button mBtnSend;private EditText mEditText;private TextView mTextView;private TextView mInputTextView;private TextView mTextViewVolume;private BookUtil mBookUtil = null;private MusicView mMusicView = null;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_music);initHandler();//初始化handler用于內(nèi)部消息處理initInComingHandler();//用于處理來(lái)自VoiceSdkService的消息initCommunicationAssist();//向application注冊(cè)消息回調(diào),VoiceSdkSerive可以//通過(guò)getServiceToActivityListener()獲得回調(diào)向MusicActivity發(fā)送消息initView();//初始化view控件Intent intent = new Intent();intent.setClass(MusicActivity.this, VoiceSdkService.class);startService(intent);//啟動(dòng)后臺(tái)服務(wù)}private void initView(){mBtnStart = (Button) findViewById(R.id.btn_start);mBtnStop = (Button) findViewById(R.id.btn_stop);mBtnCancel = (Button) findViewById(R.id.btn_cancel);mBtnSend = (Button) findViewById(R.id.btn_send);mInputTextView = (TextView) findViewById(R.id.tv_inputText);mEditText = (EditText) findViewById(R.id.et_content);mTextView = (TextView) findViewById(R.id.tv_result);mTextViewVolume = (TextView) findViewById(R.id.tv_volume);mBtnStart.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {sendMessageToService(MessageConst.CLIENT_ACTION_START_RECORED,0,0,null,null);} });mBtnStop.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {sendMessageToService(MessageConst.CLIENT_ACTION_STOP_RECORED,0,0,null,null);mBtnStart.setText("開(kāi)始");Log.i("led","MusicActivity mBtnStop onclick 開(kāi)始");} });mBtnCancel.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {sendMessageToService(MessageConst.CLIENT_ACTION_CANCEL_RECORED,0,0,null,null);} });mBtnSend.setOnClickListener(new OnClickListener(){@Overridepublic void onClick(View v) {sendMessageToService(MessageConst.CLIENT_ACTION_SENT_TEXT,0,0,null,mEditText.getText());mInputTextView.setText("文字: "+mEditText.getText());} });mMusicView = (MusicView) findViewById(R.id.music_view);//if(mMusicView != null)//mMusicView.initMusicView(MusicActivity.this,mHandler);}private void initHandler(){mHandler = new Handler(){@Overridepublic void handleMessage(Message msg){switch (msg.what){case MessageConst.CLIENT_ACTION_START_RECORED:break;default:break; }}};}//InComingHandler 收到來(lái)自VoiceSdkService的消息用于更新界面,//包括開(kāi)始錄音,結(jié)束錄音,播放的書(shū)的名稱和進(jìn)度,音量等信息。private void initInComingHandler(){mInComingHandler = new Handler(){@Overridepublic void handleMessage(Message msg){switch (msg.what){case MessageConst.CLIENT_ACTION_START_RECORED:mBtnStart.setText("錄音中");Log.i("led","MusicActivity 錄音中");break;case MessageConst.CLIENT_ACTION_STOP_RECORED:mBtnStart.setText("識(shí)別中");Log.i("led","MusicActivity 識(shí)別中");break;case MessageConst.CLIENT_ACTION_CANCEL_RECORED:mBtnStart.setText("開(kāi)始");mTextView.setText("已取消");break;case MessageConst.CLIENT_ACTION_ON_ERROR:mTextView.setText("錯(cuò)誤代碼:"+msg.arg1);mBtnStart.setText("開(kāi)始");break;case MessageConst.CLIENT_ACTION_UPDATA_VOLUME:mTextViewVolume.setText("音量: "+msg.arg1);break;case MessageConst.SERVER_ACTION_RETURN_RESULT://mTextView.setText(msg.obj.toString());mBtnStart.setText("開(kāi)始");break;case MessageConst.CLIENT_ACTION_PLAY_BOOK_AFTER_SEARCH:mBtnStart.setText("開(kāi)始");mBookUtil = BookUtil.getInstance();mBookUtil.play(msg.arg1);break;case MessageConst.CLIENT_ACTION_UPDATA_PLAYING_BOOK_NAME:mMusicView.setMusicName(msg.obj.toString());break;case MessageConst.CLIENT_ACTION_UPDATE_BOOK_PROGRESS:int current = msg.arg1;int duration = msg.arg2;mMusicView.setProgress(current*100/duration);float time = duration/1000/60;mMusicView.setTotalTime("總時(shí)間:"+time);break;case MessageConst.CLIENT_ACTION_UPDATA_INPUT_TEXT:if(msg.obj != null)mInputTextView.setText("文字: "+msg.obj.toString());break;case MessageConst.CLIENT_ACTION_UPDATA_SERVER_MESSAGE:if(msg.obj != null)mTextView.setText("服務(wù)器返回sentence: "+msg.obj.toString());break;default:break;}}};}private void initCommunicationAssist(){//向Application注冊(cè)VoiceSdkService到MusicActivity的回調(diào)mActivityComAssist = new ActivityComAssist();OlamiApplication.getInstance().setServiceToActivityListener(mActivityComAssist);}private void sendMessageToService(int what, int arg1, int arg2, Bundle data, Object obj){//向VoiceSdkService發(fā)送消息if(OlamiApplication.getInstance().getActivityToServiceListener() != null)OlamiApplication.getInstance().getActivityToServiceListener().callBack(what, arg1, arg2, data, obj);}private class ActivityComAssist implements CommunicationAssist{//實(shí)現(xiàn)CommunicationAssist借口,用于回調(diào)VoiceSdkService發(fā)送過(guò)來(lái)的消息@Overridepublic void callBack(int what, int arg1, int arg2, Bundle data,Object obj) {Message msg = Message.obtain(null, what);msg.arg1 = arg1;msg.arg2 = arg2;if (data != null)msg.setData(data);if (obj != null)msg.obj = obj;mInComingHandler.sendMessage(msg);} }@Overridepublic void onDestroy() {//退出應(yīng)用,停止VoiceSdkService,會(huì)進(jìn)行資源的釋放super.onDestroy();Intent intent = new Intent();intent.setClass(MusicActivity.this, VoiceSdkService.class);stopService(intent);} }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
3.3 VoiceSdkService
@Override public void onCreate() {initHandler();//用于內(nèi)部消息處理initInComingHandler();//用于處理來(lái)自MusicActivity的消息initCommunicationAssist();//向application注冊(cè)消息回調(diào),這樣MusicActivity可//以通過(guò)getActivityToServiceListener()回調(diào)向VoiceSdkService發(fā)送消息initViaVoiceRecognizerListener();//初始化錄音識(shí)別回調(diào)listenerinit();//olami錄音識(shí)別引擎初始化initXmly();//喜馬拉雅初始化}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
定義OlamiVoiceRecognizerListener
onError(int errCode)//出錯(cuò)回調(diào),可以對(duì)比官方文檔錯(cuò)誤碼看是什么錯(cuò)誤?
onEndOfSpeech()//錄音結(jié)束?
onBeginningOfSpeech()//錄音開(kāi)始?
onResult(String result, int type)//result是識(shí)別結(jié)果JSON字符串?
onCancel()//取消識(shí)別,不會(huì)再返回識(shí)別結(jié)果?
onUpdateVolume(int volume)//錄音時(shí)的音量,1-12個(gè)級(jí)別大小音量
下面是VoiceSdkService完整代碼:
public class VoiceSdkService extends Service{private Handler mHandler;private Handler mInComingHandler;private VoiceSdkComAssist mVoiceSdkComAssist;private OlamiVoiceRecognizer mOlamiVoiceRecognizer;private OlamiVoiceRecognizerListener mOlamiVoiceRecognizerListener;private BookUtil mBookUtil = null;private boolean mIsRecordPause = false;@Overridepublic void onCreate() {initHandler();initInComingHandler();initCommunicationAssist();initViaVoiceRecognizerListener();init();initXmly();}@Overridepublic IBinder onBind(Intent intent) {// TODO Auto-generated method stubreturn null;}public void init(){initHandler();mOlamiVoiceRecognizer = new OlamiVoiceRecognizer(VoiceSdkService.this);TelephonyManager telephonyManager=(TelephonyManager) this.getSystemService(this.getBaseContext().TELEPHONY_SERVICE);String imei=telephonyManager.getDeviceId();mOlamiVoiceRecognizer.init(imei);//set null if you do not want to notify olami server.mOlamiVoiceRecognizer.setListener(mOlamiVoiceRecognizerListener);mOlamiVoiceRecognizer.setLocalization(OlamiVoiceRecognizer.LANGUAGE_SIMPLIFIED_CHINESE);mOlamiVoiceRecognizer.setAuthorization("51a4bb56ba954655a4fc834bfdc46af1","asr","68bff251789b426896e70e888f919a6d","nli"); mOlamiVoiceRecognizer.setVADTailTimeout(2000);mOlamiVoiceRecognizer.setLatitudeAndLongitude(31.155364678184498,121.34882432933009); }private void initHandler(){mHandler = new Handler(){@Overridepublic void handleMessage(Message msg){switch (msg.what){case MessageConst.CLIENT_ACTION_START_RECORED:sendMessageToActivity(MessageConst.CLIENT_ACTION_START_RECORED,0,0,null,null);break;case MessageConst.CLIENT_ACTION_STOP_RECORED:sendMessageToActivity(MessageConst.CLIENT_ACTION_STOP_RECORED,0,0,null,null);break;case MessageConst.CLIENT_ACTION_ON_ERROR:sendMessageToActivity(MessageConst.CLIENT_ACTION_ON_ERROR,msg.arg1,0,null,null);break;case MessageConst.CLIENT_ACTION_PLAY_BOOK_AFTER_SEARCH:sendMessageToActivity(MessageConst.CLIENT_ACTION_PLAY_BOOK_AFTER_SEARCH, msg.arg1, 0, null, msg.obj);break;case MessageConst.CLIENT_ACTION_UPDATA_PLAYING_BOOK_NAME:sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_PLAYING_BOOK_NAME, msg.arg1, 0, null, msg.obj);break;case MessageConst.CLIENT_ACTION_UPDATE_BOOK_PROGRESS:sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATE_BOOK_PROGRESS, msg.arg1, msg.arg2, null, null);break;case MessageConst.CLIENT_ACTION_CANCEL_RECORED:sendMessageToActivity(MessageConst.CLIENT_ACTION_CANCEL_RECORED, msg.arg1, msg.arg2, null, null);break;default:break;}}};}private void initInComingHandler(){mInComingHandler = new Handler(){@Overridepublic void handleMessage(Message msg){switch (msg.what){case MessageConst.CLIENT_ACTION_START_RECORED:if(mOlamiVoiceRecognizer != null)mOlamiVoiceRecognizer.start(); break;case MessageConst.CLIENT_ACTION_STOP_RECORED:if(mOlamiVoiceRecognizer != null)mOlamiVoiceRecognizer.stop(); break;case MessageConst.CLIENT_ACTION_CANCEL_RECORED:if(mOlamiVoiceRecognizer != null)mOlamiVoiceRecognizer.cancel(); break;case MessageConst.CLIENT_ACTION_SENT_TEXT:if(mOlamiVoiceRecognizer != null)mOlamiVoiceRecognizer.sendText(msg.obj.toString()); break;}}};}private void initViaVoiceRecognizerListener(){mOlamiVoiceRecognizerListener = new OlamiVoiceRecognizerListener();}private class OlamiVoiceRecognizerListener implements IOlamiVoiceRecognizerListener{@Overridepublic void onError(int errCode) {mHandler.sendMessage(mHandler.obtainMessage(MessageConst.CLIENT_ACTION_ON_ERROR,errCode,0));}@Overridepublic void onEndOfSpeech() {mHandler.sendEmptyMessage(MessageConst.CLIENT_ACTION_STOP_RECORED);if(mIsRecordPause){mIsRecordPause = false;mBookUtil.resumePlay();}}@Overridepublic void onBeginningOfSpeech() {if(mBookUtil.isPlaying()){mBookUtil.pause();mIsRecordPause = true;}mHandler.sendEmptyMessage(MessageConst.CLIENT_ACTION_START_RECORED);}@Overridepublic void onResult(String result, int type) { sendMessageToActivity(MessageConst.SERVER_ACTION_RETURN_RESULT,type,0,null,result);processServiceMessage(result);}@Overridepublic void onCancel() {mHandler.sendEmptyMessage(MessageConst.CLIENT_ACTION_CANCEL_RECORED);}@Overridepublic void onUpdateVolume(int volume) {sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_VOLUME,volume,0,null,null);}}private void initCommunicationAssist(){mVoiceSdkComAssist = new VoiceSdkComAssist();OlamiApplication.getInstance().setActivityToServiceListener(mVoiceSdkComAssist);}private void initXmly(){if(mBookUtil == null){mBookUtil = BookUtil.getInstance();mBookUtil.init(VoiceSdkService.this);mBookUtil.setHandler(mHandler);}}private void processServiceMessage(String message){String input = null;String serverMessage = null;try{JSONObject jsonObject = new JSONObject(message);JSONArray jArrayNli = jsonObject.optJSONObject("data").optJSONArray("nli");JSONObject jObj = jArrayNli.optJSONObject(0);JSONArray jArraySemantic = null;if(message.contains("semantic"))jArraySemantic = jObj.getJSONArray("semantic");else{input = jsonObject.optJSONObject("data").optJSONObject("asr").optString("result");sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_INPUT_TEXT, 0, 0, null, input);serverMessage = jObj.optJSONObject("desc_obj").opt("result").toString();sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_SERVER_MESSAGE, 0, 0, null, serverMessage);return;}JSONObject jObjSemantic;JSONArray jArraySlots;JSONArray jArrayModifier;String type = null;String songName = null;String singer = null;if(jObj != null) {type = jObj.optString("type");if("musiccontrol".equals(type)){jObjSemantic = jArraySemantic.optJSONObject(0);input = jObjSemantic.optString("input");jArraySlots = jObjSemantic.optJSONArray("slots");jArrayModifier = jObjSemantic.optJSONArray("modifier");String modifier = (String)jArrayModifier.opt(0);if((jArrayModifier != null) && ("play".equals(modifier))){if(jArraySlots != null)for(int i=0,k=jArraySlots.length(); i<k; i++){JSONObject obj = jArraySlots.getJSONObject(i);String name = obj.optString("name");if("singer".equals(name))singer = obj.optString("value");else if("songname".equals(name))songName = obj.optString("value");}}else if((modifier != null) && ("stop".equals(modifier))){if(mBookUtil != null)if(mBookUtil.isPlaying())mBookUtil.stop();}else if((modifier != null) && ("pause".equals(modifier))){if(mBookUtil != null)if(mBookUtil.isPlaying())mBookUtil.pause();}else if((modifier != null) && ("resume_play".equals(modifier))){if(mBookUtil != null)mBookUtil.resumePlay();}else if((modifier != null) && ("add_volume".equals(modifier))){if(mBookUtil != null)mBookUtil.addVolume();}else if((modifier != null) && ("del_volume".equals(modifier))){if(mBookUtil != null)mBookUtil.delVolume();}else if((modifier != null) && ("next".equals(modifier))){if(mBookUtil != null)mBookUtil.next();}else if((modifier != null) && ("previous".equals(modifier))){if(mBookUtil != null)mBookUtil.prev();}else if((modifier != null) && ("play_index".equals(modifier))){int position = 0;if(jArraySlots != null)for(int i=0,k=jArraySlots.length(); i<k; i++){JSONObject obj = jArraySlots.getJSONObject(i);JSONObject jNumDetial = obj.getJSONObject("num_detail");String index = jNumDetial.optString("recommend_value");position = Integer.parseInt(index) - 1;}if(mBookUtil != null)mBookUtil.skipTo(position);}}}if(songName != null){if(singer != null){}else{mBookUtil.searchBookAndPlay(songName,0,0);}}else if(singer != null){mBookUtil.searchBookAndPlay(songName,0,0);}serverMessage = jObj.optJSONObject("desc_obj").opt("result").toString();}catch (Exception e){e.printStackTrace();}//發(fā)送消息更新語(yǔ)音識(shí)別的文字sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_INPUT_TEXT, 0, 0, null, input);//發(fā)送消息更新服務(wù)器返回的結(jié)果字符串sendMessageToActivity(MessageConst.CLIENT_ACTION_UPDATA_SERVER_MESSAGE, 0, 0, null, serverMessage);}private void sendMessageToActivity(int what, int arg1, int arg2, Bundle data, Object obj){if(OlamiApplication.getInstance().getServiceToActivityListener() != null)OlamiApplication.getInstance().getServiceToActivityListener().callBack(what, arg1, arg2, data, obj);}private class VoiceSdkComAssist implements CommunicationAssist{@Overridepublic void callBack(int what, int arg1, int arg2, Bundle data,Object obj) {Message msg = Message.obtain(null, what);msg.arg1 = arg1;msg.arg2 = arg2;if (data != null)msg.setData(data);if (obj != null)msg.obj = obj;mInComingHandler.sendMessage(msg);} }@Overridepublic void onDestroy(){super.onDestroy();if(mOlamiVoiceRecognizer != null)mOlamiVoiceRecognizer.destroy();if(mBookUtil != null){mBookUtil.destroy();}}}- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
- 190
- 191
- 192
- 193
- 194
- 195
- 196
- 197
- 198
- 199
- 200
- 201
- 202
- 203
- 204
- 205
- 206
- 207
- 208
- 209
- 210
- 211
- 212
- 213
- 214
- 215
- 216
- 217
- 218
- 219
- 220
- 221
- 222
- 223
- 224
- 225
- 226
- 227
- 228
- 229
- 230
- 231
- 232
- 233
- 234
- 235
- 236
- 237
- 238
- 239
- 240
- 241
- 242
- 243
- 244
- 245
- 246
- 247
- 248
- 249
- 250
- 251
- 252
- 253
- 254
- 255
- 256
- 257
- 258
- 259
- 260
- 261
- 262
- 263
- 264
- 265
- 266
- 267
- 268
- 269
- 270
- 271
- 272
- 273
- 274
- 275
- 276
- 277
- 278
- 279
- 280
- 281
- 282
- 283
- 284
- 285
- 286
- 287
- 288
- 289
- 290
- 291
- 292
- 293
- 294
- 295
- 296
- 297
- 298
- 299
- 300
- 301
- 302
- 303
- 304
- 305
- 306
- 307
- 308
- 309
- 310
- 311
- 312
- 313
- 314
- 315
- 316
- 317
- 318
- 319
- 320
- 321
- 322
- 323
- 324
- 325
- 326
- 327
- 328
- 329
- 330
- 331
- 332
- 333
- 334
- 335
- 336
- 337
- 338
- 339
- 340
- 341
- 342
- 343
- 344
3.4 VoiceSdkService中onResult的回調(diào)處理
在VoiceSdkService.java中processServiceMessage(String message)用于處理onResult的回調(diào)數(shù)據(jù)。例如“我要聽(tīng)三國(guó)演義”返回如下數(shù)據(jù): {"data": {"asr": {"result": "我要聽(tīng)三國(guó)演義","speech_status": 0,"final": true,"status": 0},"nli": [{"desc_obj": {"result": "正在努力搜索中,請(qǐng)稍等","status": 0},"semantic": [{"app": "musiccontrol","input": "我要聽(tīng)三國(guó)演義","slots": [{"name": "songname","value": "三國(guó)演義" }],"modifier": ["play"],"customer": "58df512384ae11f0bb7b487e"}],"type": "musiccontrol"}]},"status": "ok" }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
1)解析出nli中type類型是musiccontrol,這是語(yǔ)法返回app的類型,而這個(gè)在線聽(tīng)書(shū)的demo只關(guān)心musiccontrol這 個(gè)app類型,其他的忽略。
2)用戶說(shuō)的話轉(zhuǎn)成文字是在asr中的result中獲取?
3)在nli中的semantic中,input值是用戶說(shuō)的話,同asr中的result。?
modifier代表返回的行為動(dòng)作,此處可以看到是play就是要求播放,slots中的數(shù)據(jù)表示歌曲名稱是三國(guó)演義。?
那么動(dòng)作是play,內(nèi)容是歌曲名稱是三國(guó)演義,在這個(gè)demo中調(diào)用?
mBookUtil.searchBookAndPlay(songName,0,0);會(huì)先查詢,查詢到結(jié)果會(huì)再發(fā)播放消息要求播放,我要聽(tīng)三國(guó)演義這個(gè)流程就走完了。
4.BookUtil
說(shuō)一下搜索聽(tīng)書(shū)的實(shí)現(xiàn)過(guò)程 public void searchBookInfo(String bookName,final int index,final boolean isNeedPlay) {mBookName = bookName;Map<String, String> param = new HashMap<String, String>();param.put(DTransferConstants.SEARCH_KEY, bookName);param.put(DTransferConstants.CATEGORY_ID, "" + 3);//此處3代表搜索的是聽(tīng)書(shū)//param.put(DTransferConstants.PAGE, "" + mPageId);param.put(DTransferConstants.SORT, "asc");//返回列表的排序是正序還是逆序param.put(DTransferConstants.PAGE_SIZE, "" + PAGE_SIZE);//每頁(yè)能返回多少個(gè)查詢結(jié)果mPage = (index/PAGE_SIZE)+1;//當(dāng)前在第幾頁(yè)mPlayerManager = XmPlayerManager.getInstance(mContext);//喜馬拉雅初始化部分mPlayerManager.init(mNotificationId, null);mPlayerManager.addPlayerStatusListener(mPlayerStatusListener);mPlayerManager.addAdsStatusListener(mAdsListener);CommonRequest.getSearchedAlbums(param, new IDataCallBack<SearchAlbumList>(){@Overridepublic void onSuccess(SearchAlbumList object) { if (object != null && object.getAlbums() != null&& object.getAlbums().size() != 0){if (mSearchAlbumList == null){mSearchAlbumList = object;}else{mSearchAlbumList.getAlbums().addAll(object.getAlbums());}//mTrackAdapter.notifyDataSetChanged();Map<String, String> map = new HashMap<String, String>();map.put(DTransferConstants.ALBUM_ID, ""+object.getAlbums().get(0).getId());map.put(DTransferConstants.SORT, "asc");map.put(DTransferConstants.PAGE, "" + mPage);map.put(DTransferConstants.PAGE_SIZE, "" + PAGE_SIZE);CommonRequest.getTracks(map, new IDataCallBack<TrackList>(){@Overridepublic void onSuccess(TrackList object){mTrackList = object;mTotalCount = mTrackList.getTotalCount();if(mTrackList.getTracks().size() <= 0)return;String str = "專輯:"+mTrackList.getAlbumTitle()+get(0).getTrackTitle().toString();if(isNeedPlay){mPosition = index % PAGE_SIZE;mHandler.sendMessage(mHandler.obtainMessage(MessageConst.CLIENT_ACTION_PLAY_BOOK_AFTER_SEARCH, index % PAGE_SIZE,0));//此處mTrackList中已經(jīng)查詢出結(jié)果//向VoiceSdkService發(fā)送消息進(jìn)行播放}elsesendBookInfoToServer(); }@Overridepublic void onError(int code, String message){Log.i("ppp","error: "+message);sendBookInfoToServer();}});}}@Overridepublic void onError(int code, String message){Log.i("ppp","error: "+message);sendBookInfoToServer();}}); }- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
5.demo中支持的說(shuō)法
我想聽(tīng)西游記?
我要聽(tīng)西游記?
播放西游記?
聽(tīng)西游記?
我想聽(tīng)西游記這本書(shū)?
上一首?
上一回?
下一首?
下一回?
暫停/暫停播放?
繼續(xù)/繼續(xù)播放?
聲音大一點(diǎn)?
聲音小一點(diǎn)?
關(guān)閉/關(guān)閉播放
用的是喜馬拉雅測(cè)試賬號(hào),只支持聽(tīng)書(shū)的功能,查找歌曲的結(jié)果返回為空。
6.源碼下載鏈接
用olamisdk語(yǔ)音識(shí)別引擎做在線聽(tīng)書(shū)demo
7.相關(guān)鏈接
語(yǔ)音記賬demo:http://blog.csdn.net/ls0609/article/details/72765789
olami開(kāi)放平臺(tái)語(yǔ)法編寫簡(jiǎn)介:http://blog.csdn.net/ls0609/article/details/71624340
olami開(kāi)放平臺(tái)語(yǔ)法官方介紹:https://cn.olami.ai/wiki/?mp=nli&content=nli2.html
轉(zhuǎn)載請(qǐng)注明CSDN博文地址:http://blog.csdn.net/ls0609/article/details/71519203
總結(jié)
以上是生活随笔為你收集整理的语音识别,语义理解一站式解决(android平台olami sdk)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 用Kotlin开发android平台语音
- 下一篇: Hinton's Dark Knowle