def record_button(self):
"""
Records high quality audio files on the artist side.
:return:
"""
# Toggle recording
rec_state = self.app.get_own_state()['recording']
self.app.get_own_state()['recording'] = not rec_state
if self.app.get_own_state()['recording']:
# Update state
self.app.chat_client.send_sync(constants.SYNC_START_RECORDING)
# GUI update
self.ids.record_button.source = SessionScreen.stop_theme
# Start the progress effect
progress_thread = threading.Thread(target=self.record_progress)
progress_thread.start()
filename = self.app.config.get_file_name(self.app.session_name,
datetime.now().strftime(constants.DATETIME_HQ))
head, tail = os.path.split(filename)
print "Creating: " + tail
# Make sure folders exist
if not os.path.exists(head):
os.makedirs(head)
# Makes a Recorder with the desired filename
self.app.recorder = audio.Recorder(filename)
# Add available audio file to state list
self.app.add_audio_file(filename)
# Starts writing to an audio file, including to disk
self.app.recorder.start() # Starts recording
print "Recording..."
else:
# Update state
self.app.chat_client.send_sync(constants.SYNC_STOP_RECORDING)
# GUI update
self.ids.record_button.source = SessionScreen.record_red
# Closes recording threads
self.app.recorder.stop()
self.app.phone.stop_start_recording(datetime.now().strftime(constants.DATETIME_LQ))
self.add_clip() # adds to gui sidebar
# Send a sync message for when a clip is available
available_filename = self.app.get_latest_audio_file()
_, tail = os.path.split(available_filename)
self.app.chat_client.send_sync(constants.SYNC_FILE_AVAILABLE,
filename=tail,
length=audio.get_length(available_filename))
评论列表
文章目录