语音识别率极低
西梅内斯帕斯 发布于2015-07 浏览:13097 回复:8
0
收藏
快速回复

我在Linux用python调用RESTAPI的代码,能够成功查询,但是识别率极低,说什么都是“哈哈”,“嗯”,我播放录音文件听的还是挺清晰的,不知道为啥,代码如下:


#encoding=utf-8

import os

import wave

import urllib, urllib2, pycurl

import base64

import json

## get access token by api key & secret key


def get_token():

    apiKey = "xxx"

    secretKey = "xxx"


    auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_cre$


    res = urllib2.urlopen(auth_url)

    json_data = res.read()

    return json.loads(json_data)['access_token']


def dump_res(buf):

 print buf



## post audio to server

def use_cloud(token):

    os.system('sudo arecord -D "plughw:1,0" -d 5  tts.pcm')

    os.system('play tts.pcm')

    fp = wave.open('tts.pcm', 'rb')

    nf = fp.getnframes()

    f_len = nf * 2


    audio_data = fp.readframes(nf)


    cuid = "xxxxxxxxxx" #my xiaomi phone MAC

    srv_url = 'http://vop.baidu.com/server_api' + '?cuid=' + cuid + '&token=' +$

    http_header = [

        'Content-Type: audio/pcm; rate= 8000',

        'Content-Length: %d' % f_len

    ]

    c = pycurl.Curl()

    c.setopt(pycurl.URL, str(srv_url)) #curl doesn't support unicode

    #c.setopt(c.RETURNTRANSFER, 1)

    c.setopt(c.HTTPHEADER, http_header)   #must be list, not dict

    c.setopt(c.POST, 1)

    c.setopt(c.CONNECTTIMEOUT, 30)

    c.setopt(c.TIMEOUT, 30)

    c.setopt(c.WRITEFUNCTION, dump_res)

    c.setopt(c.POSTFIELDS, audio_data)

    c.setopt(c.POSTFIELDSIZE, f_len)

    c.perform() #pycurl.perform() has no return val


if __name__ == "__main__":

    token = get_token()

    use_cloud(token)

    os.system('sudo rm tts.pcm')




收藏
点赞
0
个赞
共8条回复 最后由用户已被禁言回复于2022-04
#9luckyToMe2回复于2020-02

看看

0
#8荒墨丶迷失回复于2017-11

猛然一看 ,怎么是两年前的帖子.....惊呆了。。

0
#7荒墨丶迷失回复于2017-11

首先音频能听清楚并不代表就能识别的,需要考虑这个音频的文件格式,采样率以及声道等一系列的参数是否正确,否则是识别不了的。

1
#6ZYuXinz回复于2017-11
#5 fujiayi1984回复
appleyuchi:    auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_cre$ 这句话好像不完整? 回复appleyuchi:感谢您的回复
展开

url = "http://tsn.baidu.com/text2audio?tex=" + saytext + "&lan=zh&cuid=08-11-96-CA-E8-98&ctp=1&per=1&tok=" + TOKEN;

 

我这样弄不行

0
#5fujiayi1984回复于2017-11

appleyuchi:

   auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_cre$

这句话好像不完整?

回复appleyuchi:感谢您的回复

0
#4appleyuchi回复于2017-11

   auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_cre$

这句话好像不完整?

0
#3q神奇物种回复于2015-08

发现不是百度的问题:

http://blog.csdn.net/wolfblood_zzx/article/details/46418635

使用pyaudio库录音就能识别了

0
#2q神奇物种回复于2015-08

我的也是,估计百度语音又犯抽了

0
TOP
切换版块