saattrupdan commited on
Commit
325f853
·
1 Parent(s): d087544

fix: Deal with None inputs in transcribe_audio function

Browse files
Files changed (1) hide show
  1. app.py +9 -2
app.py CHANGED
@@ -55,16 +55,23 @@ transcription_fixer = PunctFixer(language="da", device=device)
55
 
56
  logger.info("Models loaded, ready to transcribe audio.")
57
 
58
- def transcribe_audio(sampling_rate_and_audio: tuple[int, np.ndarray]) -> str:
59
  """Transcribe the audio.
60
 
61
  Args:
62
  sampling_rate_and_audio:
63
- A tuple with the sampling rate and the audio.
 
64
 
65
  Returns:
66
  The transcription.
67
  """
 
 
 
 
 
 
68
  sampling_rate, audio = sampling_rate_and_audio
69
  if audio.ndim > 1:
70
  audio = np.mean(audio, axis=1)
 
55
 
56
  logger.info("Models loaded, ready to transcribe audio.")
57
 
58
+ def transcribe_audio(sampling_rate_and_audio: tuple[int, np.ndarray] | None) -> str:
59
  """Transcribe the audio.
60
 
61
  Args:
62
  sampling_rate_and_audio:
63
+ A tuple with the sampling rate and the audio, or None if no audio was
64
+ provided.
65
 
66
  Returns:
67
  The transcription.
68
  """
69
+ if sampling_rate_and_audio is None:
70
+ return (
71
+ "No audio was provided. Please record or upload an audio clip, and try "
72
+ "again."
73
+ )
74
+
75
  sampling_rate, audio = sampling_rate_and_audio
76
  if audio.ndim > 1:
77
  audio = np.mean(audio, axis=1)