WeChat Small program speech recognition, synthesis

Source: Internet
Author: User

The online front of all the Small Program speech recognition blog, after the Small program API update let the students see confused, here only to describe the front-end work, after all, I am only a freshman.

Send the preview map first:

First, the following principle:

Use the Applet API to return the MP3 file after the recording is finished;

To use the method, see: Developers.weixin.qq.com/miniprogram/dev/api/getrecordermanager.html

  

There are only two formats for converting a recording to a file: ACC mp3, so the online old API returns the silk format that is obsolete.

Remember:

  Developer tools to get the MP3 connection is not available, only on the real machine debugging is returned to the local file path, this path to the recording of the MP3 file, is available.

So easy to get the mp3 file, very simple ~

Next we will use the Baidu speech recognition synthesis Api:http://ai.baidu.com/docs#/asr-api/top

Maybe look at the confused, okay ~

Baidu Voice Requirements:

Configure the Applet recording API here

  

The value of start after configuration is:

{    numberofchannels:1,    samplerate:16000,    format: ' mp3 ',    framesize:50  }

This recording after the mp3 file is Baidu voice want.

  Way One : is not to ask Baidu speech recognition does not support MP3 format Ah, this is the Java backstage thing, online Java mp3 to PCM format blog countless, Let your Java backstage to see the Baidu Voice API to get token by the way, the converted PCM format to convert text to the front desk.

Baidu is not a lot of configuration and front-end does not matter ~

A sigh of relief ~ Strong front-end of course can get back to the background transmission of PCM file address and then to adjust Baidu API.

Choose a way to skip the way two, look straight to continue.

   mode two : If the front end is going to do, look at the API details:

Address: Http://ai.baidu.com/docs#/ASR-API/top

  Again: the mp3 file after recording is converted into text. If you want the function of voice playback, please continue to look down ~ very simple

Small Program API:

Wx.createinneraudiocontext (), Address: developers.weixin.qq.com/miniprogram/dev/api/createinneraudiocontext.html

See Parameters;

Here is src is MP3 link ah, I only get backstage through the text ah.

Yes, Baidu speech synthesis API, do not go to Baidu official website to see, too simple, bong on:

tsn.baidu.com/text2audio?tok=xxxx&cuid=867905025778863&ctp=1&spd=6&lan=zh&tex=xxxx;
Tok: Baidu Voice token, ( get please see additional article )
Text: The words you want to broadcast.
This is a complete MP3 link that calls the Applet API to play directly.


  additional : Baidu token acquisition;
  
/* Baidu TTS gets token*/  export let getbaidutoken= () =>{    return new Promise ((resolve) =>{      Wx.request ({        URL:  ' openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=xxxxxxxx& Client_secret=xxxxxxxxxx ',        method: ' GET ',        success:function (r) {          resolve (R);        },        fail (res) {          wx.showtoast ({            title: "Baidu Speech synthesis Get token interface error",            icon: ' None '          })  ;}});};

Here client_id and Client_secret are registered Baidu speech recognition platform in the console created by the app obtained.

  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.