Upload soundTest.py
Browse files- soundTest.py +22 -0
soundTest.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from gtts import gTTS
|
| 2 |
+
import playsound
|
| 3 |
+
from langdetect import detect
|
| 4 |
+
|
| 5 |
+
def text_to_speech(text ):
|
| 6 |
+
tts = gTTS(text=text, lang= 'en')
|
| 7 |
+
tts.save("output.mp3")
|
| 8 |
+
playsound.playsound("output.mp3")
|
| 9 |
+
|
| 10 |
+
def main():
|
| 11 |
+
print("Enter the text you want to convert to speech:")
|
| 12 |
+
text = input()
|
| 13 |
+
|
| 14 |
+
# Detect language
|
| 15 |
+
lang = detect(text)
|
| 16 |
+
print(type(lang))
|
| 17 |
+
print(f"Detected language: {lang}")
|
| 18 |
+
|
| 19 |
+
text_to_speech(text ,)
|
| 20 |
+
|
| 21 |
+
if __name__ == "__main__":
|
| 22 |
+
main()
|