Skip to content

Commit

Permalink
notify user if no audio is recorded
Browse files Browse the repository at this point in the history
  • Loading branch information
mathewthe2 committed May 20, 2021
1 parent ad122df commit c6fcc80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions game2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def start_manual_recording(request_time, session_start_time):
def stop_manual_recording():
if manual_audio_recorder.is_recording():
create_directory_if_not_exists(manual_audio_file_path)
audio_exists = manual_audio_recorder.has_audio()
manual_audio_recorder.stop_recording(manual_audio_file_path, -1)
file_name = os.path.basename(manual_audio_file_path)
return file_name
if audio_exists:
file_name = os.path.basename(manual_audio_file_path)
return file_name
return ''

@eel.expose
Expand Down
10 changes: 8 additions & 2 deletions recordaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, deviceIndex=-1, frames=512):
self.audiofile = "out.wav"
self.duration = 10
self.frames = frames
self.hasAudio = False

def run(self):
if self.deviceIndex == -1:
Expand Down Expand Up @@ -49,9 +50,11 @@ def run(self):

# Start recording
self.isRecording = True
self.hasAudio = False
while self.bRecord:
self.recorded_frames.append(stream.read(self.frames, exception_on_overflow = True))

self.hasAudio = True

stream.stop_stream()
stream.close()

Expand Down Expand Up @@ -94,4 +97,7 @@ def restart_recording(self):
self.bRecord = False

def is_recording(self):
return self.isRecording
return self.isRecording

def has_audio(self):
return self.hasAudio
2 changes: 2 additions & 0 deletions web/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,8 @@ async function stopManualRecording() {
updateLogAudioById(logId, audioFileName);
refreshLogMenuContent(logId);
refreshCardContent(logId);
} else {
notify('No audio detected. Check your audio device in settings.')
}
}

Expand Down

0 comments on commit c6fcc80

Please sign in to comment.