Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize WeChat Mini Programs's speech recognition and Synthesis

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to realize WeChat Mini Programs's speech recognition and synthesis. The content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to realize WeChat Mini Programs's speech recognition and synthesis. Let's take a look.

First, describe the principle:

Use WeChat Mini Programs api to return the mp3 file after recording.

There are only two formats for converting recordings into files: acc mp3, so the old online APIs that return silk format are outdated.

Remember:

The MP3 connection obtained by Wechat developer tool is not available, only debugging on the real machine returns the path of the local file, this path points to the recording mp3 file, is available.

It's easy to get the mp3 file, isn't it?

Next, we will synthesize api: http://ai.baidu.com/docs#/ASR-API/top using Baidu speech recognition.

Configure WeChat Mini Programs recording api here

The value of start after configuration is:

{numberOfChannels: 1, sampleRate:16000, format: 'mp3', frameSize: 50}

In this way, the mp3 file obtained after recording is what Baidu Voice wants.

Way one: whether to ask Baidu voice recognition does not support mp3 format, this is the matter of java background, online java mp3 to pcm format of countless blogs, let your java background to see Baidu voice api to get token by the way to convert the pcm format into text to the foreground.

Whether a lot of configuration of Baidu has nothing to do with the front end ~

A sigh of relief ~ the strong front end can of course get the pcm file address transferred from the background and then transfer Baidu api.

Choose mode one, skip mode two, look at it directly and continue.

Method 2: if the front end wants to do it, please see the api explanation.

Continue: in this way, the recorded mp3 file is converted into text. If you want the function of voice playback, please continue to read on ~ it's very simple.

WeChat Mini Programs api:

Wx.createInnerAudioContext ()

Look at the parameters

What I want here is the link to src, that is, MP3. I only get the text that comes through in the background.

Yes, Baidu voice synthesis API, do not go to Baidu official website to see, too easy, here:

Https://tsn.baidu.com/text2audio?tok=xxxx&cuid=867905025778863&ctp=1&spd=6&lan=zh&tex=xxxx; tok: Baidu Voice token, (for more information) text: the text you want to broadcast. This is a complete mp3 link, which can be played directly by calling WeChat Mini Programs api. Extra: access to Baidu token / * Baidu speech synthesis acquires token*/ export let getBaiDuToken= () = > {return new Promise ((resolve) = > {wx.request ({url: 'https://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 acquisition token interface error", icon:'none'});})});}

The client_id and client_secret here are obtained by registering Baidu speech recognition platform to create an application in the console.

This is the end of the article on "how to realize WeChat Mini Programs's speech recognition and synthesis". Thank you for your reading. I believe you all have a certain understanding of the knowledge of "how to achieve WeChat Mini Programs speech recognition and synthesis". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report