-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
40 lines (34 loc) · 1.27 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
37
38
39
#!/usr/bin/env python
#-*- coding:utf-8 -*-
'''
>>> python test.py test.mp3
'''
import os, sys
from acrcloud.recognizer import ACRCloudRecognizer
if __name__ == '__main__':
config = {
'host':'ap-southeast-1.api.acrcloud.com',
'access_key':'<access_key of your project>',
'access_secret':'<access_secret of your project>',
'debug':False,
'timeout':10 # seconds
}
'''This module can recognize ACRCloud by most of audio/video file.
Audio: mp3, wav, m4a, flac, aac, amr, ape, ogg ...
Video: mp4, mkv, wmv, flv, ts, avi ...'''
re = ACRCloudRecognizer(config)
print "recognizing by file ..."
inputFile = sys.argv[1]
#recognize by file path, and skip X seconds from from the beginning of inputFile.
X = 0
print re.recognize_by_file( inputFile, X)
'''
# Another way that recognize by buffer
# inputFile must be in format: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 8000 Hz
inputFile = sys.argv[1]
buf = open( inputFile, 'rb').read()
print "recognizing by buffer ..."
#recognize by file_audio_buffer that read from file path, and skip X seconds from from the beginning of sys.argv[1].
X = 0
print re.recognize_by_filebuffer(buf, X)
'''