Skip to content

Commit e897308

Browse files
committed
python-baidu语音“
1 parent 0c14fea commit e897308

File tree

11 files changed

+20
-13
lines changed

11 files changed

+20
-13
lines changed

python_baiduyuyin/.2.py.swp

12 KB
Binary file not shown.

python_baiduyuyin/1.wav

156 KB
Binary file not shown.

python_baiduyuyin/2.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
import base64
66
import json
77
## get access token by api key & secret key
8-
8+
## 获得token,需要填写你的apikey以及secretkey
99
def get_token():
10-
apiKey = "Xv3HXWDAll8EmmZDecHcSgvn"
11-
secretKey = "eb46e9ea313aff9f3f200fb33708ae72"
10+
apiKey = "Ll0c53MSac6GBOtpg22ZSGAU"
11+
secretKey = "44c8af396038a24e34936227d4a19dc2"
1212

1313
auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + apiKey + "&client_secret=" + secretKey;
1414

@@ -17,17 +17,18 @@ def get_token():
1717
return json.loads(json_data)['access_token']
1818

1919
def dump_res(buf):
20-
print buf
20+
print (buf)
2121

2222

2323
## post audio to server
2424
def use_cloud(token):
25-
fp = wave.open('vad_0.wav', 'rb')
25+
fp = wave.open('1.wav', 'rb')
26+
##已经录好音的语音片段
2627
nf = fp.getnframes()
2728
f_len = nf * 2
2829
audio_data = fp.readframes(nf)
2930

30-
cuid = "xxxxxxxxxx" #my xiaomi phone MAC
31+
cuid = "7519663" #你的产品id
3132
srv_url = 'http://vop.baidu.com/server_api' + '?cuid=' + cuid + '&token=' + token
3233
http_header = [
3334
'Content-Type: audio/pcm; rate=8000',
@@ -48,4 +49,6 @@ def use_cloud(token):
4849

4950
if __name__ == "__main__":
5051
token = get_token()
52+
#获得token
5153
use_cloud(token)
54+
#进行处理,然后

python_baiduyuyin/2.py~

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import urllib, urllib2, pycurl
55
import base64
66
import json
77
## get access token by api key & secret key
8-
8+
## 获得token,需要填写你的apikey以及secretkey
99
def get_token():
10-
apiKey = "xxxxxxxx"
11-
secretKey = "xxxxxxxxx"
10+
apiKey = "Ll0c53MSac6GBOtpg22ZSGAU"
11+
secretKey = "44c8af396038a24e34936227d4a19dc2"
1212

1313
auth_url = "https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=" + apiKey + "&client_secret=" + secretKey;
1414

@@ -17,17 +17,18 @@ def get_token():
1717
return json.loads(json_data)['access_token']
1818

1919
def dump_res(buf):
20-
print buf
20+
print (buf)
2121

2222

2323
## post audio to server
2424
def use_cloud(token):
25-
fp = wave.open('vad_0.wav', 'rb')
25+
fp = wave.open('1.wav', 'rb')
26+
##已经录好音的语音片段
2627
nf = fp.getnframes()
2728
f_len = nf * 2
2829
audio_data = fp.readframes(nf)
2930

30-
cuid = "xxxxxxxxxx" #my xiaomi phone MAC
31+
cuid = "7519663" #你的产品id
3132
srv_url = 'http://vop.baidu.com/server_api' + '?cuid=' + cuid + '&token=' + token
3233
http_header = [
3334
'Content-Type: audio/pcm; rate=8000',
@@ -48,4 +49,6 @@ def use_cloud(token):
4849

4950
if __name__ == "__main__":
5051
token = get_token()
52+
#获得token
5153
use_cloud(token)
54+
#进行处理,然后

python_baiduyuyin/2.wav

156 KB
Binary file not shown.
-156 KB
Binary file not shown.
-156 KB
Binary file not shown.
-156 KB
Binary file not shown.
-156 KB
Binary file not shown.

python_baiduyuyin/luyin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def record_wave():
5151
count += 1
5252
print '.'
5353

54-
filename = datetime.now().strftime("%Y-%m-%d_%H_%M_%S")+".wav"
54+
#filename = datetime.now().strftime("%Y-%m-%d_%H_%M_%S")+".wav"
55+
filename = "1.wav"
5556
save_wave_file(filename, save_buffer)
5657
save_buffer = []
5758
print filename, "saved"

0 commit comments

Comments
 (0)