-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaudio2text.py
58 lines (41 loc) · 1.33 KB
/
audio2text.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import speech_recognition as sr
import boto3
import speech_recognition as sr
import os
import datetime
r = sr.Recognizer()
audio_file = sr.AudioFile("harsh.wav")
with audio_file as source:
r.adjust_for_ambient_noise(source)
audio = r.record(source)
result = r.recognize_google(audio)
with open("harsh.txt",mode ="w") as file:
file.write("Recognized text:")
file.write("\n")
file.write(result)
print("Hurray! conversion is completed")
r = sr.Recognizer()
audio_file = sr.AudioFile("download.wav")
with audio_file as source:
r.adjust_for_ambient_noise(source)
audio = r.record(source)
result = r.recognize_google(audio)
with open("test.txt",mode ="w") as file:
file.write("Recognized text:")
file.write("\n")
file.write(result)
print("Hurray! conversion is completed")
#====== make file unique
now = datetime.datetime.now()
fileun=str(now)
#=======fretching the test file
file_loc=os.path.abspath('test.txt')
print(file_loc)
#========== AWS uploding file
client = boto3.client(
's3',
aws_access_key_id='AKIA6LMBN6TNRNNGBNI5',
aws_secret_access_key='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',
)
s3=boto3.resource('s3')
s3.meta.client.upload_file('file_loc','newup1319',fileun) #newup1319 is the bucket name , file_loc is the file to send ,fileun will be show on object