首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >语音识别:一句话识别报错,求助?

语音识别:一句话识别报错,求助?

提问于 2018-12-05 22:17:12
回答 2关注 0查看 708

在调用一句话识别的接口过程中,有些文件可以识别,有些报错,看不懂是为啥,请大家帮忙看看,谢谢。

我试了两个文件,831800004885046-00-u.wav,是成功的;

831800004885046-02-u.wav,就报错了。

运行结果如图:

运行的代码如下

代码语言:js
复制
"""
    功能:调用腾讯语音识别的一句话识别接口
    版本:1.0
    日期:2018-12-5
    说明:安装腾讯最新的sdk后,直接调用
"""
from tencentcloud.common.credential import Credential
from tencentcloud.aai.v20180522.aai_client import AaiClient
from tencentcloud.aai.v20180522.models import SentenceRecognitionRequest
import base64
import json
import sys

with open(r'.\831800004885046-00-u.wav', 'rb') as f:
    file = f.read()

speech_base64 = base64.b64encode(file).decode('utf-8')
speech_length = len(file)
print(speech_length)
# 用户需修改为自己官网的appid,secretid与sectretkey
secretkey = 'IZjjesvmYSQEvTpzbDNXfVRDtOo6KqcJ'
secretid = 'AKIDUt3dzJG3wqmZEz6AXkyf5SkeTH0zhm5M'
appid = 1258179684
# 实例化认证对象,入参需要传入ID和KEY
# 就是鉴权
cred = Credential(secretId=secretid, secretKey=secretkey)

# 实例化产品
client = AaiClient(cred, "ap-chongqing")

# 实例化请求对象
param = {
    'ProjectId':appid,
    'SubServiceType':2,
    'EngSerViceType':'16k',
    'SourceType':1,
    'VoiceFormat':'wav',
    'UsrAudioKey':'shui3qing1shan1lan2',
    'Data':speech_base64,
    'DataLen':speech_length
}
req = SentenceRecognitionRequest()
req.from_json_string(json.dumps(param).encode('utf-8'))
# print(type(json.dumps(param).encode('utf-8')))
# print(sys.getsizeof(json.dumps(param).encode('utf-8')))
# 通过client对象调用访问接口,需要传入请求对象
response = client.SentenceRecognition(req)

# 输出返回信息
print(response.to_json_string())
print(type(response))
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档