forked from SRM-Hackathon/Team-Envision
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwit.py
28 lines (24 loc) · 834 Bytes
/
wit.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
import requests
import json
def read_audio(WAVE_FILENAME):
# function to read audio(wav) file
with open(WAVE_FILENAME, 'rb') as f:
audio = f.read()
return audio
def wit():
API_ENDPOINT = 'https://api.wit.ai/speech'
ACCESS_TOKEN = '45N5OTMTN3LKPDKOOYAYYABZKMARSYXP'
# get a sample of the audio that we recorded before.
audio = read_audio("corrections/path-corrected.wav")
# defining headers for HTTP request
headers = {'authorization': 'Bearer ' + ACCESS_TOKEN,
'Content-Type': 'audio/wav'}
#Send the request as post request and the audio as data
resp = requests.post(API_ENDPOINT, headers = headers,
data = audio)
#Get the text
import chardet
data= json.loads(resp.content.decode('utf-8'))
with open('text.json', 'w') as outfile:
json.dump(data, outfile)
return data