Speech Ability
Introduction
Speech Ability includes listening and speaking abilities.
Ability to listen:
ASR part returns through SkillCallback, and NLP part returns through ModuleCallBack.
Ability to speak:
A variety of speakers can be adjusted in the settings.
Create speech service callback
SkillCallback mSkillCallback = new SkillCallback() { @Override public void onSpeechParResult(String s) throws RemoteException { //The result of temporary speech recognition } @Override public void onStart() throws RemoteException { //Start recognition } @Override public void onStop() throws RemoteException { // end of recognition } @Override public void onVolumeChange(int volume) throws RemoteException { //The size of the recognized voice changes } /** * @param status 0: return normally * 1: other returns * 2: Noise or single_other return * 3: Timeout * 4: Forced to cancel * 5: The asr result ends early, without passing through NLU * 6: In the case of full duplex with the same semantics, other returns */ @Override public void onQueryEnded(int status) throws RemoteException { } @Override public void onQueryAsrResult(String asrResult) throws RemoteException { //asrResult: final recognition result } };
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Connect to speech service
final SkillApi skillApi = new SkillApi(); skillApi.connectApi(context, new ApiListener() { @Override public void handleApiDisabled() { } @Override public void handleApiConnected() { //Voice service connection is successful, register voice callback skillApi.registerCallBack(mSkillCallback); } @Override public void handleApiDisconnected() { //Voice service has been disconnected } });
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
TTS playback
Method name: playText
Call method:
skillApi.playText(text, new TextListener() { @Override public void onStart() { //Play start } @Override public void onStop() { //Play stop } @Override public void onError() { //Play error } @Override public void onComplete() { //Play is complete } });
Parameter Description:
text
: TTS playback text Note: Please avoid using long strings in TTS text that we cannot support, such as hyperlinks, scrambled character sequences, etc. This may cause program calls to fail. It is recommended to keep a single TTS playback within 300 characters, with a maximum limit of 1000 characters. If the text content is too long, it can be divided into segments for TTS playback.
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Stop TTS playback
Method name: stopTTS
Calling method:
skillApi.stopTTS();
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Set speech recognition mode
Note: The interface will only take effect when “Voice Settings” and “Continuous Pickup” are turned on in the robot settings
Method name: setRecognizeMode
Calling method:
skillApi.setRecognizeMode(isContinue);
Parameter Description:
isContinue
: boolean type, true continuous recognition false single recognition
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Turn off or turn on speech recognition
Note: The interface will only take effect when “Voice Settings” and “Continuous Pickup” are turned on in the robot settings
Method name: setRecognizable
Calling method:
skillApi.setRecognizable(enable);
Parameter Description:
enable
: boolean type, true open false close
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Set speech recognition area
Method name: setAngleCenterRange
Calling method:
skillApi.setAngleCenterRange(angleCenter, angleRange);
Only the first generation algorithm supports setting the center angle for this interface, while the second generation algorithm does not.
Parameter Description:
angleCenter
: center angle, float type, [0,360)angleRange
: interval angle, float type, 0,120
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | NO | NO | NO | Yes |
Get NLP results through text
Method name: queryByText
Calling method:
skillApi.queryByText(text);
Parameter Description:
text
: the text to be queried, String type
Note: This interface has no return value. The result of the query is returned as a voice command through onSendRequest of ModuleCallback.
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
Sound recording
This is a part about sound recording.
//Audio sampling rate (fixed 16000) private final int AUDIO_RATE = 16000; //Buffer length private final int AUDIO_BUF_LEN = 640; //Channel (stereo) int channelConfig = AudioFormat.CHANNEL_IN_STEREO; int minRecBufSize = AudioRecord.getMinBufferSize(AUDIO_RATE, channelConfig, AudioFormat.ENCODING_PCM_16BIT); int recBufSize = minRecBufSize * 2; AudioRecord audioRecorder =new AudioRecord(AudioSource.MIC, AUDIO_RATE, AudioFormat.CHANNEL_IN_STEREO, AudioFormat.ENCODING_PCM_16BIT, recBufSize); //data collection byte[] tempBufRec = new byte[AUDIO_BUF_LEN]; byte[] bfOutLeft = new byte[AUDIO_BUF_LEN / 2]; byte[] bfOutRight = new byte[AUDIO_BUF_LEN / 2]; int bufferSize = 5 * 2 * 16000; int readBytes = audioRecorder.read(tempBufRec, 0, bufferSize); if (readBytes == bufferSize) { deinterleaveData(tempBufRec, bfOutLeft, bfOutRight, bufferSize); //The separated data, bfOutLeft is the final required data } //Left and right channel data separation private void deinterleaveData(byte[] src, byte[] leftdest, byte[] rightdest, int len) { int rIndex = 0; int lIndex = 0; for (int i = 0; i <len;) { leftdest[rIndex] = src[i]; leftdest[rIndex + 1] = src[i + 1]; rIndex = rIndex + 2; rightdest[lIndex] = src[i + 2]; rightdest[lIndex + 1] = src[i + 3]; lIndex = lIndex + 2; i = i + 4; } }
Note1: All parameters are fixed parameters and cannot be changed, otherwise the data may not be collected.
Note2: All the robots don’t support VOIP/SIP protocol, even if use those settings.
There is a demo to show this function(worked with Mini): Download
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |
text to mp3
Method name: textToMp3 Notice: this API only work with Chinese Launguage.
Calling method:
boolean status = RobotApi.getInstance().textToMp3(reqId, text, path, name, new CommandListener(){ @Override public void onResult(int result, String message) { if (Definition.RESULT_OK == result) { try { JSONObject jsonObject = new JSONObject(message); int code = jsonObject.optInt("code"); String errMessage = jsonObject.optString("message"); if (code == 0) { mediaPlayer = new MediaPlayer(); mediaPlayer.setDataSource(path + File.separator + name); mediaPlayer.prepare(); mediaPlayer.start(); } else{ } } catch (JSONException | IOException e) { e.printStackTrace(); } }else { } } });
Parameter Description:
reqId
: int type command id, pass 0text
: String type to be converted textpath
: String type file pathname
: String type file namelistener
: CommandListener message callback{“code”:0, “message”:”err msg”}
Return Value:
int result 0 command executed / -1 not executed
Note:
1. To call the interface, you need the app to apply for sdcard usage rights
2. After the conversion is successful, an mp
3 file will be generated/overwritten in the specified path 3. Please manage the file yourself
Applicable Platform:
GreetBot | Mini | Lucki | DeliverBot | BigScreenBot |
---|---|---|---|---|
Yes | Yes | Yes | Yes | Yes |