微信公众平台开发模式 微信 语音识别 公众平台 消息接口 语音识别
微信公众平台下的语音识别实现流程相当复杂。
一、获取语音文件数据
目前可以通过模拟登录的方式获取语音文件
二、对语音进行编码
一般接口对编码有指定要求,所以需要转码
三、提交数据到第三方接口
获取识别结果与置信度,取最高值
<?php $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.google.com/speech-api/v1/recognize?xjerr=1&client=chromium&lang=zh-CN&maxresults=10"); curl_setopt($ch, CURLOPT_VERBOSE, 0); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents('1.flac')); curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: audio/x-flac; rate=16000")); $data = curl_exec($ch); curl_close($ch); if ($data=json_decode($data,true)) { echo "<ul>"; foreach($data['hypotheses'] as $i) echo "<li>".$i['utterance']."</li>"; echo "</ul>"; } else { echo "<i>识别出错</i>"; } ?>
四、语义识别
通过语法规则对结果进行分析,可同时使用分词的方法来分析
五、
其他:文本转语音
Google Text to Speech API
Base URL: http://translate.google.com/translate_tts
It converts written words into audio. It accepts GET
requests.
GET
q
The query string to convert to audio
tl
Translation language, for example, ar
for Arabic, or en-us
for English
ie
Encoding format, use default UTF-8
Examples
This is an example for Arabic "السلام عليكم"
http://translate.google.com/translate_tts?ie=UTF-8&q=%D8%A7%D9%84%D8%B3%D9%84%D8%A7%D9%85%20%D8%B9%D9%84%D9%8A%D9%83%D9%85&tl=ar
This is an example for English "Hello World"
http://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20World&tl=en-us