Python Mini Projects (Part 3)

1. Real time Speech Translation system

  • Have you ever wondered how you can communicate with someone who speaks a different language in real time? A real-time speech translation system makes this possible! This project demonstrates how to create a system that translates spoken language into another language using Python.
  • Python’s method for real-time speech translation: Start by installing the required libraries using pip. Install speech_recognition for speech-to-text conversion, googletrans for translation, and pyttsx3 or gTTS for text-to-speech.

  • Use a microphone to capture speech and transcribe it into text with the speech_recognition library. Next, utilize the googletrans library to translate the text into the target language. Finally, convert the translated text into speech using a text-to-speech library and play the audio.

				
					import speech_recognition as sr
from googletrans import Translator
import pyttsx3

# Initialize modules
recognizer = sr.Recognizer()
translator = Translator()
tts_engine = pyttsx3.init()

def translate_speech():
    with sr.Microphone() as source:
        print("Speak something...")
        try:
            audio = recognizer.listen(source)
            text = recognizer.recognize_google(audio)
            print(f"Original: {text}")

            # Translate
            translated = translator.translate(text, src='en', dest='fr')
            print(f"Translated: {translated.text}")

            # Text-to-speech
            tts_engine.say(translated.text)
            tts_engine.runAndWait()

        except Exception as e:
            print(f"Error: {e}")

translate_speech()

				
			
  • In short, a real-time speech translation system is an excellent tool for breaking language barriers. With Python, you can efficiently combine speech recognition, translation, and text-to-speech to create an intuitive solution for global communication

Tech Amplifier Final Logo