-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudioToText.py
More file actions
40 lines (27 loc) · 1.03 KB
/
AudioToText.py
File metadata and controls
40 lines (27 loc) · 1.03 KB
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
import speech_recognition as sr
import time
#necessário estar conectado a internet
#Funcao converter áudio para texto
def main():
#Caminho para o arquivo de audio
pathFile = "audioFile.wav"
#utilizando recognizer do speech_recognition
rec = sr.Recognizer()
with sr.WavFile(pathFile) as source:
print("Convertendo audio para texto...")
#Armazenando o audio
audio = rec.listen(source)
try:
#Passando o audio para o reconhecedor de padroes.
convertion = rec.recognize_google(audio,language="pt-BR")
except Exception as e:
print(e)
#Criando arquivo com texto do audio
fileExport = open('textFile.txt','w')
#escrevendo o texto capturado
fileExport.write(convertion)
#Fechando arquivo
fileExport.close()
print('Audio convertido com sucesso!')
if __name__ == "__main__":
main()