-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvoiceRecordText.py
39 lines (29 loc) · 920 Bytes
/
voiceRecordText.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
# voiceRecordText.py
# Author: Team 20
# Created: March 2015
# Summary: This file will deal with the voice
# record functionality of the project. It will
# allow for the voice to be recorded while being written into
# a file. Also, it will open the file it was written into.
import speech_recognition as sr
import platform
import os
system = platform.system()
def recordVoice():
newfile = open('newrecordfile.txt', 'w')
r = sr.Recognizer()
r.energy_threshold = 2000
with sr.Microphone() as source:
audio = r.listen(source)
# listen for the first phrase and extract it into audio data
try:
text = r.recognize(audio)
newfile.write(text)
except LookupError:
newfile.write("Could not understand audio")
newfile.close()
def openNewFile():
if system == "Darwin":
os.system("open newrecordfile.txt")
elif system == "Linux":
os.system("gedit newrecordfile.txt")