iisadia commited on
Commit
ba95f50
Β·
verified Β·
1 Parent(s): dc6e9c6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -35,6 +35,7 @@ def process_audio(audio_bytes):
35
  waveform = resampler(waveform)
36
  return {"raw": waveform.numpy().squeeze(), "sampling_rate": 16000}
37
 
 
38
  def get_voice_transcription(state_key):
39
  """Display audio recorder for a given key.
40
  If new audio is recorded, transcribe it and update the session state.
@@ -51,17 +52,19 @@ def get_voice_transcription(state_key):
51
  current_hash = hashlib.md5(audio_bytes).hexdigest()
52
  last_hash_key = state_key + "_last_hash"
53
  if st.session_state.get(last_hash_key, "") != current_hash:
54
- st.session_state[last_hash_key] = current_hash
 
55
  try:
56
- audio_input = process_audio(audio_bytes)
57
- whisper = load_voice_model()
58
- transcribed_text = whisper(audio_input)["text"]
59
- st.info(f"πŸ“ Transcribed: {transcribed_text}")
60
- # Append (or set) new transcription
61
- st.session_state[state_key] += (" " + transcribed_text).strip()
62
- st.experimental_rerun()
63
- except Exception as e:
64
- st.error(f"Voice input error: {str(e)}")
 
65
  return st.session_state[state_key]
66
 
67
  ######################################
 
35
  waveform = resampler(waveform)
36
  return {"raw": waveform.numpy().squeeze(), "sampling_rate": 16000}
37
 
38
+
39
  def get_voice_transcription(state_key):
40
  """Display audio recorder for a given key.
41
  If new audio is recorded, transcribe it and update the session state.
 
52
  current_hash = hashlib.md5(audio_bytes).hexdigest()
53
  last_hash_key = state_key + "_last_hash"
54
  if st.session_state.get(last_hash_key, "") != current_hash:
55
+ st.session_sta
56
+ te[last_hash_key] = current_hash
57
  try:
58
+ with st.spinner('πŸ”Š Processing your voice...'):
59
+ audio_input = process_audio(audio_bytes)
60
+ whisper = load_voice_model()
61
+ transcribed_text = whisper(audio_input)["text"]
62
+ st.info(f"πŸ“ Transcribed: {transcribed_text}")
63
+ # Append (or set) new transcription
64
+ st.session_state[state_key] += (" " + transcribed_text).strip()
65
+ st.experimental_rerun()
66
+ except Exception as e:
67
+ st.error(f"Voice input error: {str(e)}")
68
  return st.session_state[state_key]
69
 
70
  ######################################