我正在尝试更新Kivy中的Label以说出程序录制音频的时间。我有一个问题,PyAudio部分接管线程,并且在记录之前发送到标签的文本没有更新。
更新:文字"录制......"没有出现在标签上。
这是我的代码(没有更新):
self.answer.text = "Recording..."
lib.record.record_audio()
self.answer.text = "Converting to text..."
然后我使用标准的PyAudio进行录制:
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()
由于
更新:包括全班致电
有问题的功能:
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]
它被称为:
record_button = Button(text="Rec.", size_hint=(0.15, 1))
record_button.bind(on_press=self.record_clicked)
top_layout.add_widget(record_button)