mirror of
https://github.com/metafy-social/python-scripts.git
synced 2024-11-23 20:11:10 +00:00
Merge pull request #138 from lordvader501/text-to-speech
fixed some bugs in issue #135
This commit is contained in:
commit
46c3c6b88a
|
@ -4,6 +4,5 @@ This is a simple script that lets you convert text to speech and store it in .mp
|
|||
#### Usage
|
||||
|
||||
* Clone the repo
|
||||
* download the requirements
|
||||
* change the input in script.py
|
||||
* run python script.py
|
||||
* download the requirements using `pip install -i requirements.txt`
|
||||
* run `python script.py`
|
|
@ -1 +1,2 @@
|
|||
gtts
|
||||
playsound==1.2.2
|
|
@ -1,26 +1,61 @@
|
|||
# Import the required module for text
|
||||
# to speech conversion
|
||||
from gtts import gTTS
|
||||
|
||||
# This module is imported so that we can
|
||||
# play the converted audio
|
||||
from playsound import playsound
|
||||
import os
|
||||
|
||||
# The text that you want to convert to audio
|
||||
mytext = 'Welcome to geeksforgeeks!'
|
||||
mytext = input("Enter text: ")
|
||||
|
||||
# Language in which you want to convert
|
||||
language = 'en'
|
||||
print("MENU\n1. English (Australia)\n2. English (United Kingdom)\n3. English (United States)\n4. English (Canada)\n5. English (India)\n6. English (Ireland)\n7. English (South Africa)\n8. French (Canada)\n9. French (France)\n10. Mandarin (China Mainland)\n11. Mandarin (Taiwan)\n12. Portuguese (Brazil)\n13. Portuguese (Portugal)\n14. Spanish (Mexico)\n15. Spanish (Spain)\n16. Spanish (United States)")
|
||||
option = int(input("Select option: "))
|
||||
if option == 1:
|
||||
language = 'en'
|
||||
tld1 = 'com.au'
|
||||
if option == 2:
|
||||
language = 'en'
|
||||
tld1 = 'co.uk'
|
||||
if option == 3:
|
||||
language = 'en'
|
||||
tld1 = 'com'
|
||||
if option == 4:
|
||||
language = 'en'
|
||||
tld1 = 'ca'
|
||||
if option == 5:
|
||||
language = 'en'
|
||||
tld1 = 'co.in'
|
||||
if option == 6:
|
||||
language = 'en'
|
||||
tld1 = 'ie'
|
||||
if option == 7:
|
||||
language = 'en'
|
||||
tld1 = 'co.za'
|
||||
if option == 8:
|
||||
language = 'fr'
|
||||
tld1 = 'ca'
|
||||
if option == 9:
|
||||
language = 'fr'
|
||||
tld1 = 'fr'
|
||||
if option == 10:
|
||||
language = 'zh-CN'
|
||||
tld1 = 'com'
|
||||
if option == 11:
|
||||
language = 'zh-TW'
|
||||
tld1 = 'com'
|
||||
if option == 12:
|
||||
language = 'pt'
|
||||
tld1 = 'com.br'
|
||||
if option == 13:
|
||||
language = 'pt'
|
||||
tld1 = 'pt'
|
||||
if option == 14:
|
||||
language = 'es'
|
||||
tld1 = 'com.mx'
|
||||
if option == 15:
|
||||
language = 'es'
|
||||
tld1 = 'es'
|
||||
if option == 16:
|
||||
language = 'es'
|
||||
tld1 = 'com'
|
||||
|
||||
# Passing the text and language to the engine,
|
||||
# here we have marked slow=False. Which tells
|
||||
# the module that the converted audio should
|
||||
# have a high speed
|
||||
myobj = gTTS(text=mytext, lang=language, slow=False)
|
||||
|
||||
# Saving the converted audio in a mp3 file named
|
||||
# welcome
|
||||
myobj.save("welcome.mp3")
|
||||
|
||||
# Playing the converted file
|
||||
os.system("mpg321 welcome.mp3")
|
||||
tts = gTTS(text=mytext, tld=tld1, lang=language, slow=False)
|
||||
audio_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "tts.mp3")
|
||||
tts.save(audio_file)
|
||||
playsound(audio_file)
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user