Skip to content

With the help from a Youtube channel tutorial video, Chat GPT instructions and professional web search, I was able develop a program that I'd never think I could

License

Notifications You must be signed in to change notification settings

AndreCoutinhom/voice_translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 

Repository files navigation

lab

Voice Translator


voice_translator

This project was based on a video tutorial by @Ai_Austin. The repository contain Python files in wich it recieves audio in several languages - with focus on portuguese translations, since is my native language - and prompt commands for libraries installation in Shell. Besides, it uses an updated version of Google Trans API.

The Video 📽️

Published in 2023 march 16th by @Ai_Austin, "Create an AI Voice Translator in 4 Minutes (Python Tutorial)", is a Python programming video tutorial that shows how to create a voice translator. The code is mainly based on python and google libraries and is runned in Visual Studio Code. The program is capable of listening to the user's voice through the machine's main audio input device, collecting a text version of the audio, translate it, and returning the translated text accompanied by a computer voice dictation.

The original AI_Austin's code is set as shown below:

import speech_recognition as sr
import pyttsx3
from langdetect import detect
from googletrans import Translator

# create a recognizer object, a translator object and a Text-to-Speech object

r = sr.Recognizer()
translator = Translator(service_urls=['translate.google.com'])
tts = pyttsx3.init()

while True:
    # use the default microphone as the audio source
    with sr.Microphone() as source:
        print("Speak something...")
        # adjust the ambient noise level
        r.adjust_for_ambient_noise(source)
        # listen for audio input from the user
        audio = r.listen(source)
    try:
        # recognize speech using Google Speech Recognition 
        text = r.recognize_google(audio)
        input_language = detect(text)
        # translate speech to English if detected language is Spanish
        if input_language == "es":
            translation = translator.translate(text, dest='en')
            print(f"Translated to English: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        # translate speech to Spanish if detected language in English
        elif input_language == "en":
            translation = translator.translate(text, dest='es')
            print(f"Translated to Spanish: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        else:
            print("Unsupported language")
    except sr.UnknownValueError:
        print("Google Speech Recognition could not understand audio.")
    except sr.RequestError as e:
        print("Could not request results from Google Speech Recognition service: {e}")

Austin Dobbins' Github and Youtube Channel 🤖


Ai_Austin

Self Proclaimed Description

AI enthusiast and educator, passionate about sharing ideas and knowledge about AI, Python, programming, and technology. Let's learn and grow together!

Differences between codes 👨‍💻

There were barely none different coding structure between mine's and Austin's. In fact, the whole code was developed by watching Austin's tutorial. However, following some researches and Chat GPT's orientations through some issues I had to deal with, like code not working, bugs and syntax errors; I couldn't rely entirely on the tutorial, since some of the indicated libraries were not fully updated by the time I wrote the code myself, especially the Google trans API, responsible for the translation algorithm. That's why, on this repository, I have committed a Shell structured prompt list containing the updated version of the Google Trans API as followed below:

pip install googletrans-py
pip install --upgrade googletrans==4.0.0-rc1

Besides that, AI_Austin's tutorial has a truly functional code and a much valid programming logic.

Important notes 📒

This program has been tested and updated until 2023 August 15th. Until this date, some of the libraries have been quite troublesome. The program itself is unnable to understand any language that is not english. Despite some changes on my personal document, the bug seems to be quite ambitious.

The document titled as "voice_translator_simple_version.py" is the one version that seems to work properly, since it doesn't consider any language other than english. The version translate any english said line into a portuguese:

if input_language == "en":
            translation = translator.translate(text, dest='por')
            print(f"Translated to Portuguese: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        else:
            print("Unsupported language")

I have tested with different languages other than portuguese, and it seems to work well. Since I'm using a machine settled to portuguese speaker country, it shows an accent with a non realistic pronunciation, but there are no troubles with the code logic or the libraries. Anyone can use it as an english voice translator by changing the output language. Here are a couple of examples using spanish, japanese and german:

if input_language == "en":
            translation = translator.translate(text, dest='es')
            print(f"Translated to Portuguese: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        else:
            print("Unsupported language")

if input_language == "en":
            translation = translator.translate(text, dest='ja')
            print(f"Translated to Portuguese: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        else:
            print("Unsupported language")

if input_language == "en":
            translation = translator.translate(text, dest='de')
            print(f"Translated to Portuguese: {translation.text}")
            # speak the translated text
            tts.say(translation.text)
            tts.runAndWait()
        else:
            print("Unsupported language")

I still hope to be part of a project that can make this system actually work and do the good I believe it can for society.

Innovative Potentials 🧠

On a bright future, I would like to investigate ways to use this kind of software into corporate tech solutions. I imagine a device with an audio and visual interface that can be used to instantly translate what people are saying. This innovative solution can bring wonders for international relationships professionals.

About

With the help from a Youtube channel tutorial video, Chat GPT instructions and professional web search, I was able develop a program that I'd never think I could

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published