Spaces:
Build error
Build error
Update app.py
Browse files
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.
|
|
|
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
| 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 |
######################################
|