In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge points about how to develop voice password red packet Mini Program. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article, let's take a look at it.
The recording naturally calls the native interface provided by Mini Program, but what is rather awkward here is that the recording format of Wechat is .recording. The method of searching on the Internet is to convert the .browse format to wav or MP3 format, and then call the interfaces of major cloud service platforms to achieve voice recognition.
Https://github.com/kn007/silk... is used here The library provided is used to convert to wav format, and then use Baidu's open speech recognition interface https://ai.baidu.com/tech/spe.... To recognize the voice results.
The business implementation steps are as follows:
1. The front end realizes the recording function.
Upload .audio voice files via 2.upload API and store them in the library.
3. Trigger the speech recognition task and return the success to the front end (asynchronous)
4. The front end polls the identification results.
Because it is a time-consuming operation from upload to recognition to return results, the recognition process is best done asynchronously. (step 3)
Upload voice API part code:
/ /... Business code outline
$voice = $this- > getCreatedVoiceByBody (); / / upload and store
$this- > identifyVoice ($voice); / / trigger speech recognition task
/ /...
Public function identifyVoice ($voice)
{
WorkerUtil::sendTaskByRouteAndParams ('task/detectvoice', [' voiceid' = > $voice- > id, 'type' = >' redpack'])
}
As you can see above, a record id and its type containing the address of the voice file are sent to the back-end task service.
The backend task service processes as follows:
Class DetectVoice extends Action
{
Public function run ($voiceid, $type = 'redpack')
{
If ($type = = 'redpack') {
$voice = Voices::findOne ($voiceid)
$url = $voice- > voice
$saveName ='/ runtime/redpack-'.$voiceid.'.silk'
$convertName ='/ runtime/redpack-'.$voiceid.'.wav'
}
$this- > saveToLocalByRemoteVoiceUrlAndLocalFileName ($url, $saveName)
$cfg = [
'appKey' = >' xxx'
'appSecret' = >' xxx'
'appId' = >' xxx'
]
$util = new BaiduVoiceUtil ($cfg)
$code = exec ("bash / www/silk-v3-decoder/converter.sh {$saveName} wav")
If ($code = = 0) {
$result = $util- > asr ($convertName)
If ($result ['err_no'] = = 0) {
$voicesResult = json_encode ($result ['result'], JSON_UNESCAPED_UNICODE)
$voice- > result = $voicesResult
$voice- > save ()
@ unlink ($saveName)
@ unlink ($convertName)
}
}
The processing logic of task service is also very clear: receive the voiceid to be identified, find the record, download the voice file to a local tmp directory, call shell to convert the format, call the converted format to baidu's voice interface for recognition, and then store the results in the database.
These are all the contents of the article "how to develop Voice password Red packet Mini Program". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.