![]() ![]() #Translates user input and creates text to speech audio if st.button('Translate'): result = anslate(input_text, lang_tgt = 'ja') st.success(result) speech = gTTS(text = result, lang = 'ja', slow = False) speech.save('user_trans.mp3') audio_file = open('user_trans.mp3', 'rb') audio_bytes = audio_file.read() st.audio(audio_bytes, format='audio/ogg',start_time=0) After this, the result is also passed into the gtts function to convert to audio and then loaded to enable playback. The following code then gets the input text from the user and passes it into the translate function to convert to Japanese. #image for top of the screen image = Image.open('translate.png') st.image(image) #date display now = dt.date.today() #Text Display st.write(f"Today is ") st.write(f"Translate your thoughts.") input_text = st.text_input('Enter whatever') This involved showing the date using the datetime package and displaying text using the write() function. The next block of code involves setting up the main displays and buttons. import streamlit as st import datetime as dt from gtts import gTTS import speech_recognition as sr from google_trans_new import google_translator from PIL import Image ![]() I had a few issues initially installing the streamlit library so there may be some issues depending on your version of python. Google translator was then used to convert English text to Japanese. The gtts library is Google’s text-to-speech API to read out the final translation, while the speech_recognition library was used to transcribe the audio. The initial set up of the code involved importing the relevant libraries needed for the app. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |