I am trying to update a Label in Kivy to say when the program is recording audio. I am having a problem where the PyAudio part takes over the thread and the text sent just before the record to the label doesn't update.
Update: the text "Recording..." is not appearing on the label.
Here is my code (that doesn't update):
self.answer.text = "Recording..."
lib.record.record_audio()
self.answer.text = "Converting to text..."
And then I am using the standard PyAudio for recording:
import pyaudio
import wave
def record_audio():
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
print("* recording")
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print("* done recording")
stream.stop_stream()
stream.close()
p.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
Thanks
Update: Including full class call
The function in question:
def record_clicked(self, btn):
self.answer.text = "Recording..." #Doesn't display
# uncomment the below line to input a new wave file
lib.record.record_audio() #Takes 5 seconds
self.answer.text = "Converting to text..." #Doesn't display
analyzed_tuple = lib.record.analyze_audio() #Takes around ten seconds
self.answer.text = analyzed_tuple[1] #Displays
self.search.text = analyzed_tuple[0]
Where it is called:
record_button = Button(text="Rec.", size_hint=(0.15, 1))
record_button.bind(on_press=self.record_clicked)
top_layout.add_widget(record_button)