Skip to content

saeidsaadatigero/Voice-Recognition--Translator--Text-to-Speech

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

This Python code implements a simple voice recognition and translation system. Here’s a breakdown of what each part of the code does:

⭐⭐⭐⭐⭐1. Voice Recognition

  • Library Used: speech_recognition
  • Function: voice_to_text()
    • This function listens for audio input from the microphone.
    • It uses Google’s speech recognition service to convert the spoken audio (in Persian) into text.
    • If successful, it returns the recognized text; if it fails to understand the audio or if there's a request error, it handles those exceptions by printing error messages.

2. Translation

  • Library Used: googletrans
  • Function: translate_text(text, dest_language='en')
    • This function takes a string of text and translates it into the specified destination language (default is English).
    • It uses the Google Translate API to perform the translation and returns the translated text.

3. Text-to-Speech

  • Library Used: gtts (Google Text-to-Speech)
  • Function: text_to_speech(text)
    • This function converts the provided text into speech.
    • It saves the audio as an MP3 file and plays it using the default media player on the system (the command is specific to Windows).

4. Reading Words Separately

  • Function: read_words(text)
    • This function splits the translated text into individual words and uses the text_to_speech function to read each word aloud one by one.

5. Combining All Steps

  • Function: main()
    • This function orchestrates the entire process:
      1. It calls voice_to_text() to get the user's spoken input.
      2. It prints the recognized text.
      3. It translates the recognized text into English using translate_text().
      4. It prints the translated text.
      5. It converts the translated text to speech and reads each word separately.

6. Execution

  • The if __name__ == "__main__": block ensures that main() is called when the script is run directly.

Summary

In summary, this code captures spoken input in Persian, translates it to English, and then converts the translated text back into speech, allowing for a seamless interaction between voice and text in different languages.

About

Voice Recognation,Translator, Text-to-Speech

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published