Skip to content

Commit

Permalink
Merge pull request #127 from Ultimecia1463/ultimecia-patch-1
Browse files Browse the repository at this point in the history
feat: add replay and audio download option
  • Loading branch information
UppuluriKalyani authored Oct 9, 2024
2 parents 35e12e9 + 6917918 commit 853ceca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions Natural Language Processing/Translator-app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ def main():
audio_file = capture_and_translate(source_lang, target_lang)
if audio_file:
time.sleep(1) # Ensure pygame cleanup

# Replay the audio if available
if st.button("🔁 Replay Translated Audio", key="replay_button"):
st.audio(audio_file)

# Download the audio file
with open(audio_file, "rb") as audio:
st.download_button(
label="🔊 Download Translated Audio",
data=audio,
file_name="translated_audio.mp3",
mime="audio/mp3"
)

# Optionally delete the file afterward (if no replay needed)
try:
os.remove(audio_file)
except Exception as e:
Expand Down
8 changes: 5 additions & 3 deletions Natural Language Processing/Translator-app/translation.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,11 @@ def capture_and_translate(source_lang, target_lang):
return audio_file

except sr.WaitTimeoutError:
st.error("⚠️ No speech detected. Try speaking louder.")
st.error("⚠️ No speech detected within the time limit. Please ensure you're speaking into the microphone clearly and check your microphone settings.")
except sr.UnknownValueError:
st.error("⚠️ Could not recognize speech.")
st.error("⚠️ Speech was unclear or not recognized. Try speaking louder, clearer, or checking your microphone setup.")
except sr.RequestError:
st.error("⚠️ Could not request results from the speech recognition service. Please check your internet connection or try again later.")
except Exception as e:
st.error(f"⚠️ Error: {str(e)}")
st.error(f"⚠️ An unexpected error occurred: {str(e)}")
return None

0 comments on commit 853ceca

Please sign in to comment.