May 21, 2021 WeChat Mini Program Development Document
WeChat simultaneous interpretation plug-in is WeChat self-researched speech input, text translation and other functions of the plug-in package, used to provide third-party small program calls.
Provide real-time flow recognition capabilities of voice.Implementation by getting globally unique speech recognition manager RecordRecomanager
RecordRecomanager object's method list:
method | parameter | illustrate |
---|---|---|
start | options | Start identification |
stop | End identification | |
onStart | callback | This event is called when you start recording recognition. |
onRecognize | callback | This event is called when there is a new identification content. |
onStop | callback | Identification end event |
onError | callback | Identify error event |
Start (Options) Description:
Attributes | type | Required | Defaults | illustrate |
---|---|---|---|---|
duration | Number | no | 60000 | Specifies the length of the record, the unit MS, the maximum is 60000.If you have passed the legitimate duration, you will automatically stop recording after reaching the specified Duration. |
lang | String | no | zh_CN | Identify language, currently support zh_CN en_US zh_HK sichuanhua |
OnStart (Callback) callback result Description:
Attributes | type | illustrate |
---|---|---|
msg | String | Default OK |
OnStop (Callback) callback result Description:
Attributes | type | illustrate |
---|---|---|
tempFilePath | String | Recording temporary file address |
duration | Number | Recording total length, unit: ms |
fileSize | Number | File size, unit: B |
result | String | Final recognition result |
OneRror (Callback) callback result description:
Attributes | type | illustrate |
---|---|---|
retcode | Int | error code |
msg | String | Error message |
OnRecognize (Callback) callback result description:
Attributes | type | illustrate |
---|---|---|
result | String | Recognition result |
OneRror error code description:
Error code | Description |
---|---|
-30001 | There was an error with the recording interface |
-30002 | The recording pause interface is called, the recording is terminated, and the recognition is terminated |
-30003 | The data transfer failed because the recording frame data was not generated or the sending failure |
-30004 | Unsealed recognition results due to network or other abnormal states |
-30005 | An internal error in the speech recognition service |
-30006 | The speech recognition service was not recognized within a limited time |
-30007 | The start start parameter is wrong |
-30008 | The network failed to query the request |
-30009 | The internal failure to create the forensics |
-30010 | The network failed to send the forensics |
-30011 | An attempt to call start again in the process of identification is to return an error, and the identification task in progress is progressing normally |
-30012 | The stop error is called while the current unrecognized task is in place |
-30013 | Other unknown errors |
-40001 | The interface call frequency limit has been reached |
Example code:
//app.json
{
...
"plugins": {
...
"WechatSI": {
"version": "0.0.7",
"provider": "wx069ba97219f66d99"
}
}
}
//index.js
var plugin = requirePlugin("WechatSI")
let manager = plugin.getRecordRecognitionManager()
manager.onRecognize = function(res) {
console.log("current result", res.result)
}
manager.onStop = function(res) {
console.log("record file path", res.tempFilePath)
console.log("result", res.result)
}
manager.onStart = function(res) {
console.log("成功开始录音识别", res)
}
manager.onError = function(res) {
console.error("error msg", res.msg)
}
manager.start({duration:30000, lang: "zh_CN"})
Text translation is currently supported in zh_CN (Chinese mainland) en_US (English)
Translate (object) Description:
The name of the argument | Type | Required | Description |
---|---|---|---|
lfrom | String | Is | Text Language zh_CN (Chinese mainland) en_US (English) |
lto | String | Is | Target Language zh_CN (Chinese mainland) en_US (English) |
content | String | Is | Text content that needs to be translated, with a background limit of 1000 bytes |
Tts | Boolean | Whether | Whether or not to make speech synthesis of translation results, the default is false, not speech synthesis |
success | Function | Whether | Callback that was triggered when the call was successful |
fail | Function | Whether | Callback that was triggered when the call failed |
complete | Function | Whether | Callback function at end of interface call (call succeeds, fails are executed) |
Description of the result of the callback
Property | Type | Description |
---|---|---|
retcode | Int | The translation was successful when retcode was 0 |
origin | String | The original text |
result | String | Translation results |
filename | String | Speech address returned by speech synthesis, only Chinese speech |
expired_time | Int | Speech synthesis link time-out timestamps such as 1525930552 cannot be played after a timeout and can be used for 3 hours |
success return code description: Translation succeeds, synthesis fails to call the success callback
The status code | Description |
---|---|
0 | The translation synthesis was successful |
-10006 | The translation was successful and the internal error was synthesized |
-10007 | The translation was successful and an unsupported speech synthesis language was passed in |
-10008 | The translation was successful and the speech synthesis reached the frequency limit |
Callback callback result description
Property | Type | Description |
---|---|---|
retcode | Int | Error code |
msg | String | The error message |
Fail error code description:
Error code | Description |
---|---|
-10001 | The language check is incorrect |
-10002 | The content to be translated entered is not in the correct format |
-10003 | Incoming text content that is too long to be translated |
-10004 | There was an internal logic error in translation |
-10005 | The request failed to send, please check the network |
-40001 | If the frequency of interface calls is limited, contact the plug-in developer |
The sample code
plugin.translate({
lfrom:"en_US",
lto:"zh_CN",
content:"hello, this is the first time to test?",
success: function(res) {
if(res.retcode == 0) {
console.log("result", res.result)
} else {
console.warn("翻译失败", res)
}
},
fail: function(res) {
console.log("网络失败",res)
}
})
Languages supported by speech synthesis zh_CN (Chinese mainland), en_US (ENGLISH)
TextToSpeech (object) Description:
The name of the argument | Type | Required | Description |
---|---|---|---|
Lang | String | Is | Text language zh_CN (Chinese mainland) en_US (US) |
content | String | Is | Text content that needs to be translated is limited to 1000 bytes in the background |
success | Function | Callback that was triggered when the call was successful | |
fail | Function | Callback that was triggered when the call failed |
Description of the result of the callback
Property | Type | Description |
---|---|---|
retcode | Int | The request was successful when retcode was 0 |
origin | String | The original text |
filename | String | The voice address returned by the speech composition, which can be downloaded and used by itself |
expired_time | Int | Speech synthesis link time-out timestamp such as 1525930552, after the time-out can not be played, the use time is 3 hours |
Success return code description:
The status code | Description |
---|---|
0 | The speech synthesis was successful |
Callback callback result description
Property | Type | Description |
---|---|---|
retcode | Int | Error code |
msg | String | The error message |
Fail error code description:
Error code | Description |
---|---|
-20001 | There was an error in the speech synthesis language format |
-20002 | The input to be composited is not in the correct format |
-20003 | An internal error in speech synthesis |
-20005 | Network error |
-40001 | If the frequency of interface calls is limited, contact the plug-in developer |
The sample code
plugin.textToSpeech({
lang: "zh_CN",
tts: true,
content: "一个常见的需求",
success: function(res) {
console.log("succ tts", res.filename)
},
fail: function(res) {
console.log("fail tts", res)
}
})
The base library version is 1.9.94
Due to resource constraints, there is a quota limit for each interface call at present, if the business has special and additional needs, please contact the mailbox [email protected] request, the mail quota template is as follows. V oice input quota: 250 bars per small program, 3w bars per day. T ext translation quota: 500 times per minute, 10w times per day per small program. Speech synthesis quota: 100 times/min, 2w times/day per small program.
Company Profile: (Individuals fill in individuals)
Introduction to the small program:
Small appid:
Apply for interface name:
Current user number: (currently not online to fill in none)
Current call volume: (currently not online to fill in none)
Application quota: xx times/minute, xx times/day.
Reasonable quota inference (please provide usage scenario, expected user volume, user frequency, peak hours, average length/word length):