1 #!/usr/bin/python
2 # -*- coding: UTF-8 -*-
3 from aip import AipSpeech
4
5 #从百度AI开放平台创建应用处获取
6 APP_ID = \'\'
7 API_KEY = \'\'
8 SECRET_KEY = \'\'
9
10 client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
11
12 # 读取文件
13 def get_file_content(filePath):
14 with open(filePath, \'rb\') as fp:
15 return fp.read()
16
17 # 识别本地文件
18 def get_text():
19 result = client.asr(get_file_content(\'record.wav\'), \'wav\', 16000, {
20 \'dev_pid\': 1536,})
21 print(result)
22 text = result[\'result\'][0]
23 return text
24
25 print(get_text())