From 497294002a73d32016ad34206a3c9dc079bdfdcb Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:51:08 +0530 Subject: [PATCH 1/7] Add files via upload --- Machine_Learning/Translator App/Readme (1).md | 72 +++++++++++++++++++ Machine_Learning/Translator App/main.py | 37 ++++++++++ .../Translator App/requirements.txt | 5 ++ .../Translator App/translation.py | 58 +++++++++++++++ Machine_Learning/Translator App/utils.py | 14 ++++ 5 files changed, 186 insertions(+) create mode 100644 Machine_Learning/Translator App/Readme (1).md create mode 100644 Machine_Learning/Translator App/main.py create mode 100644 Machine_Learning/Translator App/requirements.txt create mode 100644 Machine_Learning/Translator App/translation.py create mode 100644 Machine_Learning/Translator App/utils.py diff --git a/Machine_Learning/Translator App/Readme (1).md b/Machine_Learning/Translator App/Readme (1).md new file mode 100644 index 0000000000..fbaf73f167 --- /dev/null +++ b/Machine_Learning/Translator App/Readme (1).md @@ -0,0 +1,72 @@ +# Translator App + +🎯 **Goal** +The goal of this project is to provide a real-time language translation system that captures speech, translates it into a chosen language, and plays the translated speech back to the user. + +🧵 **Dataset** +No dataset is required for this project as it uses live speech capture and Google's translation services. + +🧾 **Description** +This project allows users to translate spoken language into another language in real time. It captures the user’s voice input, translates it using Google’s translation API, and plays the translation back in audio format using Google Text-to-Speech (gTTS). + +🧮 **What I had done!** +- Built a user-friendly interface with Streamlit for language selection and speech input. +- Used the `speech_recognition` library to capture live speech from the microphone. +- Implemented Google Translate for text translation between languages. +- Played back translated speech using `gTTS` and `pygame`. + +🚀 **Models Implemented** +No machine learning models were used, but the project leverages Google Translate and Text-to-Speech APIs for translation and speech synthesis. + +📚 **Libraries Needed** +- `Streamlit` + + - **Purpose**: Streamlit is an open-source framework to build web apps for data science and machine learning. + - **Features**: + - Turns Python scripts into interactive web applications. + - Supports integration with multiple data visualization libraries (e.g., Matplotlib, Plotly). + - Instantaneously updates the app during development with live reloading. +- `SpeechRecognition` + + - **Purpose**: A Python library for converting spoken language into written text. + - **Features**: + - Supports multiple speech recognition engines and APIs, including Google Web Speech API. + - Can recognize audio from microphones, files, and other audio streams. + - Handles speech in various formats such as `.wav`, `.aiff`, and more. + +- `googletrans` + + - **Purpose**: Python library for interacting with the Google Translate API. + - **Features**: + - Provides translation between multiple languages. + - Automatically detects the language of the input text. + - Can retrieve translations and pronunciations of text in different languages. + +- `gTTs` + + - **Purpose**: Python library for interfacing with Google’s Text-to-Speech API. + - **Features**: + - Converts text into spoken language with high-quality voice output. + - Supports a wide range of languages and dialects. + - Can save the output as `.mp3` files or play them directly in the application. + +- `Pygame` + + - **Purpose**: A set of Python modules designed for multimedia application development, especially games. + - **Features**: + - Enables easy creation of 2D games with support for sound, graphics, and input. + - Cross-platform compatibility (Windows, Mac, Linux). + - Includes modules for handling images, sound, fonts, events, and input (keyboard, mouse, etc.). + +📊 **Exploratory Data Analysis Results** +Not applicable for this project as it doesn’t involve data analysis. + +📈 **Performance of the Models based on Accuracy Scores** +Not applicable. + +📢 **Conclusion** +The Translator App offers a seamless, real-time translation experience. With a simple UI, users can quickly translate and hear the translated speech in a wide variety of languages. + +✒️ **Your Signature** +Navya +GitHub: https://github.com/770navyasharma diff --git a/Machine_Learning/Translator App/main.py b/Machine_Learning/Translator App/main.py new file mode 100644 index 0000000000..c269ea54a8 --- /dev/null +++ b/Machine_Learning/Translator App/main.py @@ -0,0 +1,37 @@ +import streamlit as st +from translation import capture_and_translate +from utils import LANGUAGES +import time +import os + +# Load custom CSS +def load_css(): + with open("assets/styles.css") as f: + st.markdown(f"", unsafe_allow_html=True) + +# UI Structure +def main(): + st.title("🌐Real-Time Language Translator") + st.markdown("Translate spoken language into other languages in real-time with a sleek experience.") + + load_css() # Load custom styling + + # Language selection + source_lang_name = st.selectbox("🌍 Select Source Language", list(LANGUAGES.keys())) + target_lang_name = st.selectbox("🔄 Select Target Language", list(LANGUAGES.keys())) + + source_lang = LANGUAGES[source_lang_name] + target_lang = LANGUAGES[target_lang_name] + + # Button to start listening + if st.button("🎤 Start Listening", key="listen_button"): + audio_file = capture_and_translate(source_lang, target_lang) + if audio_file: + time.sleep(1) # Ensure pygame cleanup + try: + os.remove(audio_file) + except Exception as e: + st.error(f"⚠️ Error while deleting the file: {str(e)}") + +if __name__ == "__main__": + main() diff --git a/Machine_Learning/Translator App/requirements.txt b/Machine_Learning/Translator App/requirements.txt new file mode 100644 index 0000000000..def4522672 --- /dev/null +++ b/Machine_Learning/Translator App/requirements.txt @@ -0,0 +1,5 @@ +streamlit +googletrans==4.0.0rc1 +gtts +pygame +SpeechRecognition diff --git a/Machine_Learning/Translator App/translation.py b/Machine_Learning/Translator App/translation.py new file mode 100644 index 0000000000..0558adcba9 --- /dev/null +++ b/Machine_Learning/Translator App/translation.py @@ -0,0 +1,58 @@ +import speech_recognition as sr +from googletrans import Translator +from gtts import gTTS +import pygame +import streamlit as st + +# Initialize recognizer and translator +recognizer = sr.Recognizer() +translator = Translator() + +# Function to capture and translate speech +def capture_and_translate(source_lang, target_lang): + with sr.Microphone() as source: + st.info("🎙️ Listening... Speak now.") + + recognizer.adjust_for_ambient_noise(source, duration=1) + recognizer.energy_threshold = 200 + + try: + # Capture speech + audio = recognizer.listen(source, timeout=15, phrase_time_limit=15) + st.success("🔄 Processing...") + + # Recognize speech + text = recognizer.recognize_google(audio, language=source_lang) + st.write(f"🗣️ Original ({source_lang}): {text}") + + # Translate speech + translation = translator.translate(text, src=source_lang, dest=target_lang) + st.write(f"🔊 Translated ({target_lang}): {translation.text}") + + # Convert translation to speech + tts = gTTS(text=translation.text, lang=target_lang) + audio_file = "translated_audio.mp3" + tts.save(audio_file) + + # Play the audio + pygame.mixer.init() + pygame.mixer.music.load(audio_file) + pygame.mixer.music.play() + + st.audio(audio_file) + + while pygame.mixer.music.get_busy(): + pygame.time.Clock().tick(10) + + pygame.mixer.music.stop() + pygame.mixer.quit() + + return audio_file + + except sr.WaitTimeoutError: + st.error("⚠️ No speech detected. Try speaking louder.") + except sr.UnknownValueError: + st.error("⚠️ Could not recognize speech.") + except Exception as e: + st.error(f"⚠️ Error: {str(e)}") + return None diff --git a/Machine_Learning/Translator App/utils.py b/Machine_Learning/Translator App/utils.py new file mode 100644 index 0000000000..fffcdb410d --- /dev/null +++ b/Machine_Learning/Translator App/utils.py @@ -0,0 +1,14 @@ +# Available languages dictionary +LANGUAGES = { + 'English': 'en', + 'Hindi': 'hi', + 'Tamil': 'ta', + 'Telugu': 'te', + 'Marathi': 'mr', + 'Bengali': 'bn', + 'Gujarati': 'gu', + 'Kannada': 'kn', + 'Malayalam': 'ml', + 'Punjabi': 'pa', + 'Urdu': 'ur' +} From fab11286a38f1b0e8c7fd5da8d9782bbcab9c6cc Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:53:31 +0530 Subject: [PATCH 2/7] Delete Machine_Learning/Readme.md --- Machine_Learning/Readme.md | 72 -------------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 Machine_Learning/Readme.md diff --git a/Machine_Learning/Readme.md b/Machine_Learning/Readme.md deleted file mode 100644 index fbaf73f167..0000000000 --- a/Machine_Learning/Readme.md +++ /dev/null @@ -1,72 +0,0 @@ -# Translator App - -🎯 **Goal** -The goal of this project is to provide a real-time language translation system that captures speech, translates it into a chosen language, and plays the translated speech back to the user. - -🧵 **Dataset** -No dataset is required for this project as it uses live speech capture and Google's translation services. - -🧾 **Description** -This project allows users to translate spoken language into another language in real time. It captures the user’s voice input, translates it using Google’s translation API, and plays the translation back in audio format using Google Text-to-Speech (gTTS). - -🧮 **What I had done!** -- Built a user-friendly interface with Streamlit for language selection and speech input. -- Used the `speech_recognition` library to capture live speech from the microphone. -- Implemented Google Translate for text translation between languages. -- Played back translated speech using `gTTS` and `pygame`. - -🚀 **Models Implemented** -No machine learning models were used, but the project leverages Google Translate and Text-to-Speech APIs for translation and speech synthesis. - -📚 **Libraries Needed** -- `Streamlit` - - - **Purpose**: Streamlit is an open-source framework to build web apps for data science and machine learning. - - **Features**: - - Turns Python scripts into interactive web applications. - - Supports integration with multiple data visualization libraries (e.g., Matplotlib, Plotly). - - Instantaneously updates the app during development with live reloading. -- `SpeechRecognition` - - - **Purpose**: A Python library for converting spoken language into written text. - - **Features**: - - Supports multiple speech recognition engines and APIs, including Google Web Speech API. - - Can recognize audio from microphones, files, and other audio streams. - - Handles speech in various formats such as `.wav`, `.aiff`, and more. - -- `googletrans` - - - **Purpose**: Python library for interacting with the Google Translate API. - - **Features**: - - Provides translation between multiple languages. - - Automatically detects the language of the input text. - - Can retrieve translations and pronunciations of text in different languages. - -- `gTTs` - - - **Purpose**: Python library for interfacing with Google’s Text-to-Speech API. - - **Features**: - - Converts text into spoken language with high-quality voice output. - - Supports a wide range of languages and dialects. - - Can save the output as `.mp3` files or play them directly in the application. - -- `Pygame` - - - **Purpose**: A set of Python modules designed for multimedia application development, especially games. - - **Features**: - - Enables easy creation of 2D games with support for sound, graphics, and input. - - Cross-platform compatibility (Windows, Mac, Linux). - - Includes modules for handling images, sound, fonts, events, and input (keyboard, mouse, etc.). - -📊 **Exploratory Data Analysis Results** -Not applicable for this project as it doesn’t involve data analysis. - -📈 **Performance of the Models based on Accuracy Scores** -Not applicable. - -📢 **Conclusion** -The Translator App offers a seamless, real-time translation experience. With a simple UI, users can quickly translate and hear the translated speech in a wide variety of languages. - -✒️ **Your Signature** -Navya -GitHub: https://github.com/770navyasharma From 6460e73238f99f7bae6c90464f45dcb1675ab05e Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:53:48 +0530 Subject: [PATCH 3/7] Delete Machine_Learning/main.py --- Machine_Learning/main.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) delete mode 100644 Machine_Learning/main.py diff --git a/Machine_Learning/main.py b/Machine_Learning/main.py deleted file mode 100644 index c269ea54a8..0000000000 --- a/Machine_Learning/main.py +++ /dev/null @@ -1,37 +0,0 @@ -import streamlit as st -from translation import capture_and_translate -from utils import LANGUAGES -import time -import os - -# Load custom CSS -def load_css(): - with open("assets/styles.css") as f: - st.markdown(f"", unsafe_allow_html=True) - -# UI Structure -def main(): - st.title("🌐Real-Time Language Translator") - st.markdown("Translate spoken language into other languages in real-time with a sleek experience.") - - load_css() # Load custom styling - - # Language selection - source_lang_name = st.selectbox("🌍 Select Source Language", list(LANGUAGES.keys())) - target_lang_name = st.selectbox("🔄 Select Target Language", list(LANGUAGES.keys())) - - source_lang = LANGUAGES[source_lang_name] - target_lang = LANGUAGES[target_lang_name] - - # Button to start listening - if st.button("🎤 Start Listening", key="listen_button"): - audio_file = capture_and_translate(source_lang, target_lang) - if audio_file: - time.sleep(1) # Ensure pygame cleanup - try: - os.remove(audio_file) - except Exception as e: - st.error(f"⚠️ Error while deleting the file: {str(e)}") - -if __name__ == "__main__": - main() From 66bb14c5ae0bb04e2a6062170e6bb2b007df735f Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:54:02 +0530 Subject: [PATCH 4/7] Delete Machine_Learning/requirements.txt --- Machine_Learning/requirements.txt | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 Machine_Learning/requirements.txt diff --git a/Machine_Learning/requirements.txt b/Machine_Learning/requirements.txt deleted file mode 100644 index def4522672..0000000000 --- a/Machine_Learning/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -streamlit -googletrans==4.0.0rc1 -gtts -pygame -SpeechRecognition From 155ab25864fe6da0097ad77467bd7f3cb587d935 Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:54:16 +0530 Subject: [PATCH 5/7] Delete Machine_Learning/translation.py --- Machine_Learning/translation.py | 58 --------------------------------- 1 file changed, 58 deletions(-) delete mode 100644 Machine_Learning/translation.py diff --git a/Machine_Learning/translation.py b/Machine_Learning/translation.py deleted file mode 100644 index 0558adcba9..0000000000 --- a/Machine_Learning/translation.py +++ /dev/null @@ -1,58 +0,0 @@ -import speech_recognition as sr -from googletrans import Translator -from gtts import gTTS -import pygame -import streamlit as st - -# Initialize recognizer and translator -recognizer = sr.Recognizer() -translator = Translator() - -# Function to capture and translate speech -def capture_and_translate(source_lang, target_lang): - with sr.Microphone() as source: - st.info("🎙️ Listening... Speak now.") - - recognizer.adjust_for_ambient_noise(source, duration=1) - recognizer.energy_threshold = 200 - - try: - # Capture speech - audio = recognizer.listen(source, timeout=15, phrase_time_limit=15) - st.success("🔄 Processing...") - - # Recognize speech - text = recognizer.recognize_google(audio, language=source_lang) - st.write(f"🗣️ Original ({source_lang}): {text}") - - # Translate speech - translation = translator.translate(text, src=source_lang, dest=target_lang) - st.write(f"🔊 Translated ({target_lang}): {translation.text}") - - # Convert translation to speech - tts = gTTS(text=translation.text, lang=target_lang) - audio_file = "translated_audio.mp3" - tts.save(audio_file) - - # Play the audio - pygame.mixer.init() - pygame.mixer.music.load(audio_file) - pygame.mixer.music.play() - - st.audio(audio_file) - - while pygame.mixer.music.get_busy(): - pygame.time.Clock().tick(10) - - pygame.mixer.music.stop() - pygame.mixer.quit() - - return audio_file - - except sr.WaitTimeoutError: - st.error("⚠️ No speech detected. Try speaking louder.") - except sr.UnknownValueError: - st.error("⚠️ Could not recognize speech.") - except Exception as e: - st.error(f"⚠️ Error: {str(e)}") - return None From 7c9d9fad0493e1c7df565b5c7def286705ceb3f9 Mon Sep 17 00:00:00 2001 From: Tanishq Kolhatkar <91214235+tanishqkolhatkar93@users.noreply.github.com> Date: Sat, 26 Oct 2024 20:54:32 +0530 Subject: [PATCH 6/7] Delete Machine_Learning/utils.py --- Machine_Learning/utils.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 Machine_Learning/utils.py diff --git a/Machine_Learning/utils.py b/Machine_Learning/utils.py deleted file mode 100644 index fffcdb410d..0000000000 --- a/Machine_Learning/utils.py +++ /dev/null @@ -1,14 +0,0 @@ -# Available languages dictionary -LANGUAGES = { - 'English': 'en', - 'Hindi': 'hi', - 'Tamil': 'ta', - 'Telugu': 'te', - 'Marathi': 'mr', - 'Bengali': 'bn', - 'Gujarati': 'gu', - 'Kannada': 'kn', - 'Malayalam': 'ml', - 'Punjabi': 'pa', - 'Urdu': 'ur' -} From af3d0bfc16e9b09c30c7007c6fad8a83b0b904aa Mon Sep 17 00:00:00 2001 From: tanishqkolhatkar93 Date: Tue, 29 Oct 2024 11:43:24 +0000 Subject: [PATCH 7/7] updating Project-Structure.md --- Project-Structure.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Project-Structure.md b/Project-Structure.md index 55da925de4..0e31c34573 100644 --- a/Project-Structure.md +++ b/Project-Structure.md @@ -704,6 +704,10 @@ * [Db](Machine_Learning/Signature_verification_portal/db.py) * Style Transfer With Neural Network * [Style Transfer With Neural Networks](Machine_Learning/Style%20Transfer%20with%20Neural%20Network/Style%20Transfer%20with%20Neural%20Networks.ipynb) + * Translator App + * [Main](Machine_Learning/Translator%20App/main.py) + * [Translation](Machine_Learning/Translator%20App/translation.py) + * [Utils](Machine_Learning/Translator%20App/utils.py) * Twitter Sentiment Analysis * [Twitter Sentiment Analysis](Machine_Learning/Twitter%20Sentiment%20Analysis/Twitter%20Sentiment%20Analysis.ipynb) * Wecare @@ -714,13 +718,10 @@ * [Web Page Phishing Detection](Machine_Learning/Web%20Page%20Phishing%20Detection/web_page_phishing_detection.ipynb) * Zomato Restaurant Clustering And Sentiment Analysis * [Zomato Restaurant Clustering And Sentiment Analysis](Machine_Learning/Zomato%20Restaurant%20Clustering%20and%20Sentiment%20Analysis/Zomato_Restaurant_Clustering_and_Sentiment_Analysis.ipynb) - * [Main](Machine_Learning/main.py) * Pokemon-Data-Analysis-And-Legendary-Classification-Main * [Data-Analysis-Advance-Modelling-On-Pokemons](Machine_Learning/pokemon-data-analysis-and-legendary-classification-main/data-analysis-advance-modelling-on-pokemons.ipynb) * Smartphone Rate Prediction * [Main](Machine_Learning/smartphone_rate_prediction/main.py) - * [Translation](Machine_Learning/translation.py) - * [Utils](Machine_Learning/utils.py) ## Sentiment-Analysis-Of-Restaurant-Reviews * [Sentiment Analysis Of Restaurant Reviews](Sentiment-Analysis-Of-Restaurant-Reviews/Sentiment%20Analysis%20of%20Restaurant%20Reviews.ipynb)