-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
36 lines (30 loc) · 1.04 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import sys
from aip import AipSpeech
from openpyxl.compat import file
""" 你的 APPID AK SK """
APP_ID = '14913816'
API_KEY = 'muqbMozoGOA42hI9EhSbxqWf'
SECRET_KEY = 'vO42mvMOAbGiuVBLNWzsl0rZ08TczF1a'
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
return fp.read()
# 识别本地文件
txt_path = str(sys.argv[1])
temp_path = str(sys.argv[2])
rootDir = temp_path
for lists in os.listdir(rootDir):
f2 = open(txt_path, 'a+')
files_temp=rootDir+'/'+lists
cy = client.asr(get_file_content(str(files_temp)), 'wav', 16000, {'dev_pid': 1537})
print(cy)
if ("result" in cy.keys()):
f2.write(str(cy['result']))
f2.write("\n")
print('success in writing!')
else:
f2.write(" ******* skip few words ****** ")
f2.close()
# cy = client.asr(get_file_content(str('C:/Users\epic_cy\Desktop\WavCut-master\WavCut-master\MusicResult/3.wav')), 'wav', 16000, {'dev_pid': 1537})
# print(cy)