我使用的服务是:语音识别
调用的接口是:rest api
参数设置情况:
开发平台和机型:windows python语言
SDK版本号:
代码或日志截图(上传截图能帮助您更快解决问题):
# -*- coding: utf-8 -*-#Api_Key申请的api_key
#Secrect_Key对应的secret_key
#获取token
import urllib.request
import urllib
import json
import base64
import os
Api_Key='kmRHqoqox3eqRws59uqoGePerGb3xn0z'
Secrect_Key='UbinySmZx6I1pFraLezcL7Rc3pOg7GiV'
url = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id='+Api_Key+'&client_secret='+Secrect_Key
res = urllib.request.urlopen(url).read()
data = json.loads(res)
token = data['access_token'] #获取的token
print('token获取成功:',token)
#提交数据
VOICE_RATE = 8000
#WAVE_FILE = 'temp.wav'
WAVE_FILE ='test.pcm'
USER_ID = '7988339'
#WAVE_TYPE = 'wav'
WAVE_TYPE ='pcm'
#其它参数可参考sdk文档
f = open(WAVE_FILE,'rb') #在这离读取的时候用二进制形式读取
speech = bytes.decode(base64.b64encode(f.read()))
print (type(speech))
size = os.path.getsize(WAVE_FILE)
update = json.dumps({'format':WAVE_TYPE,'rate':VOICE_RATE,'channel':1,'cuid':USER_ID,'token':token,'speech':speech,'len':size})
r = urllib.request.urlopen(url,str.encode(update))
#处理json
t = r.read()
print(r.getcode())#输出200表示请求成功完成
#这里没有收到回复
result = json.loads(t)
print(type(result))
print(result)
复现步骤、现象及其他描述:
结果只返回
{
"access_token": "24.7d69b22d69ed5b7f23ae0280550e3b5e.2592000.1488183879.282335-7988339",
"refresh_token": "25.fee8db1184d79ad1d9f68787a2814ed9.315360000.1800951879.282335-7988339",
"scope": "public audio_voice_assistant_get wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian wangrantest_test wangrantest_test1 bnstest_test1 bnstest_test2 ApsMisTest_Test权限",
"session_key": "9mzdDFFMdxsDqbmIWiVCZQTGAUH8XejWR+fO3EzBZy771LpeZ4PxG0bQhgigY7jdVqHH+g3oYYpYOQb8VV9WvepasT1b",
"session_secret": "6a4af8e2af5ceb70084da89a7cf433d8",
"expires_in": 2592000
}
没有返回语音识别的内容
收藏
点赞
0
个赞
请登录后评论
TOP
切换版块
回复泪线111:
谢谢对百度语音的支持!
nickms:
回复泪线111:
您好,识别的地址是http://vop.baidu.com/server_api,代码中的url是获取token的url。
过程应该是先调用https://openapi.baidu.com/oauth/2.0/token获取token,
再调用调用http://vop.baidu.com/server_api获取识别的结果
回复nickms:谢谢,已经成功了,是我编写的过程没有彻底搞清楚,麻烦了
回复泪线111:
您好,识别的地址是http://vop.baidu.com/server_api,代码中的url是获取token的url。
过程应该是先调用https://openapi.baidu.com/oauth/2.0/token获取token,
再调用调用http://vop.baidu.com/server_api获取识别的结果
泪线111:
我使用的服务是:语音识别
调用的接口是:rest api
参数设置情况:
开发平台和机型:windows python语言
SDK版本号:
代码或日志截图(上传截图能帮助您更快解决问题):
# -*- coding: utf-8 -*-#Api_Key申请的api_key
#Secrect_Key对应的secret_key
#获取token
import urllib.request
import urllib
import json
import base64
import os
Api_Key='kmRHqoqox3eqRws59uqoGePerGb3xn0z'
Secrect_Key='UbinySmZx6I1pFraLezcL7Rc3pOg7GiV'
url = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id='+Api_Key+'&client_secret='+Secrect_Key
res = urllib.request.urlopen(url).read()
data = json.loads(res)
token = data['access_token'] #获取的token
print('token获取成功:',token)
#提交数据
VOICE_RATE = 8000
#WAVE_FILE = 'temp.wav'
WAVE_FILE ='test.pcm'
USER_ID = '7988339'
#WAVE_TYPE = 'wav'
WAVE_TYPE ='pcm'
#其它参数可参考sdk文档
f = open(WAVE_FILE,'rb') #在这离读取的时候用二进制形式读取
speech = bytes.decode(base64.b64encode(f.read()))
print (type(speech))
size = os.path.getsize(WAVE_FILE)
update = json.dumps({'format':WAVE_TYPE,'rate':VOICE_RATE,'channel':1,'cuid':USER_ID,'token':token,'speech':speech,'len':size})
r = urllib.request.urlopen(url,str.encode(update))
#处理json
t = r.read()
print(r.getcode())#输出200表示请求成功完成
#这里没有收到回复
result = json.loads(t)
print(type(result))
print(result)
复现步骤、现象及其他描述:
结果只返回
{
"access_token": "24.7d69b22d69ed5b7f23ae0280550e3b5e.2592000.1488183879.282335-7988339",
"refresh_token": "25.fee8db1184d79ad1d9f68787a2814ed9.315360000.1800951879.282335-7988339",
"scope": "public audio_voice_assistant_get wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian wangrantest_test wangrantest_test1 bnstest_test1 bnstest_test2 ApsMisTest_Test权限",
"session_key": "9mzdDFFMdxsDqbmIWiVCZQTGAUH8XejWR+fO3EzBZy771LpeZ4PxG0bQhgigY7jdVqHH+g3oYYpYOQb8VV9WvepasT1b",
"session_secret": "6a4af8e2af5ceb70084da89a7cf433d8",
"expires_in": 2592000
}
没有返回语音识别的内容
回复泪线111:我估计时python不支持pcm文件的直接读取
泪线111:
我使用的服务是:语音识别
调用的接口是:rest api
参数设置情况:
开发平台和机型:windows python语言
SDK版本号:
代码或日志截图(上传截图能帮助您更快解决问题):
# -*- coding: utf-8 -*-#Api_Key申请的api_key
#Secrect_Key对应的secret_key
#获取token
import urllib.request
import urllib
import json
import base64
import os
Api_Key='kmRHqoqox3eqRws59uqoGePerGb3xn0z'
Secrect_Key='UbinySmZx6I1pFraLezcL7Rc3pOg7GiV'
url = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id='+Api_Key+'&client_secret='+Secrect_Key
res = urllib.request.urlopen(url).read()
data = json.loads(res)
token = data['access_token'] #获取的token
print('token获取成功:',token)
#提交数据
VOICE_RATE = 8000
#WAVE_FILE = 'temp.wav'
WAVE_FILE ='test.pcm'
USER_ID = '7988339'
#WAVE_TYPE = 'wav'
WAVE_TYPE ='pcm'
#其它参数可参考sdk文档
f = open(WAVE_FILE,'rb') #在这离读取的时候用二进制形式读取
speech = bytes.decode(base64.b64encode(f.read()))
print (type(speech))
size = os.path.getsize(WAVE_FILE)
update = json.dumps({'format':WAVE_TYPE,'rate':VOICE_RATE,'channel':1,'cuid':USER_ID,'token':token,'speech':speech,'len':size})
r = urllib.request.urlopen(url,str.encode(update))
#处理json
t = r.read()
print(r.getcode())#输出200表示请求成功完成
#这里没有收到回复
result = json.loads(t)
print(type(result))
print(result)
复现步骤、现象及其他描述:
结果只返回
{
"access_token": "24.7d69b22d69ed5b7f23ae0280550e3b5e.2592000.1488183879.282335-7988339",
"refresh_token": "25.fee8db1184d79ad1d9f68787a2814ed9.315360000.1800951879.282335-7988339",
"scope": "public audio_voice_assistant_get wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian wangrantest_test wangrantest_test1 bnstest_test1 bnstest_test2 ApsMisTest_Test权限",
"session_key": "9mzdDFFMdxsDqbmIWiVCZQTGAUH8XejWR+fO3EzBZy771LpeZ4PxG0bQhgigY7jdVqHH+g3oYYpYOQb8VV9WvepasT1b",
"session_secret": "6a4af8e2af5ceb70084da89a7cf433d8",
"expires_in": 2592000
}
没有返回语音识别的内容
回复泪线111:我估计是python不支持pcm文件的直接读取