-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.py
More file actions
68 lines (59 loc) · 2.3 KB
/
Copy pathTest.py
File metadata and controls
68 lines (59 loc) · 2.3 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.textinput import TextInput
import speech_recognition as sr
class RecorderApp(App):
def build(self):
# This will automatically load the kv file
return self.layout
def toggle_recording(self):
# Your existing toggle_recording logic
pass
class RecorderApp(App):
def build(self):
self.recorder = Recorder()
self.layout = BoxLayout(orientation='vertical')
self.start_stop_button = Button(text='Start Recording')
self.start_stop_button.bind(on_press=self.toggle_recording)
self.text_display = TextInput(readonly=True, halign="left")
self.layout.add_widget(self.start_stop_button)
self.layout.add_widget(self.text_display)
return self.layout
def toggle_recording(self, instance):
if self.recorder.getRecordingStatus():
self.recorder.setRecordingStatus(False)
instance.text = 'Start Recording'
self.text_display.text = self.recorder.full_text
else:
self.recorder.setRecordingStatus(True)
instance.text = 'Stop Recording'
self.recorder.RecordAndConvertToText()
class Recorder:
def __init__(self):
self.r = sr.Recognizer()
self.textList = []
self.full_text = ""
self.recordingStatus = False
def getRecordingStatus(self):
return self.recordingStatus
def setRecordingStatus(self, status):
self.recordingStatus = status
def RecordAndConvertToText(self):
try:
while self.recordingStatus:
with sr.Microphone() as source:
audio = self.r.listen(source)
try:
currentLine = self.r.recognize_google(audio)
self.textList.append(currentLine)
except sr.UnknownValueError:
pass # or handle the error as you see fit
except sr.RequestError as e:
pass # or handle the error as you see fit
self.full_text = "\n".join(self.textList)
except KeyboardInterrupt:
self.save_text_to_file("my_recorded_text.txt")
if __name__ == '__main__':
RecorderApp().run()