Added awesome STT and TTS features :)

This commit is contained in:
nsde 2022-12-27 15:26:22 +01:00
parent d30d919358
commit ce38f81115
3 changed files with 10 additions and 5 deletions

View file

@ -38,5 +38,6 @@ sudo apt-get install python3-pyaudio
``` ```
## Example tasks ## Example tasks
- what wifi am I connected with on Linux - What WiFi am I connected with (on Linux)?
- - Tell me a short story!
- Translate "Hello there"!

View file

@ -7,7 +7,7 @@ def ask() -> str:
with sr.Microphone() as source2: with sr.Microphone() as source2:
recognizer.adjust_for_ambient_noise(source2, duration=1) recognizer.adjust_for_ambient_noise(source2, duration=1)
recording = recognizer.listen(source2, timeout=5) recording = recognizer.listen(source2, timeout=5)
return recognizer.recognize_google(recording, language='de-DE') return recognizer.recognize_google(recording, language='en-US') # lang.detect(text)[1]
except sr.RequestError: except sr.RequestError:
return 'I did not understand what you said.' return 'I did not understand what you said.'

View file

@ -2,9 +2,13 @@ import os
import gtts import gtts
import playsound import playsound
def say(text): from . import lang
tts = gtts.gTTS(text=text, lang='de') #, lang='en'
def say(text: str) -> None:
"""Says a plain text using Google TTS."""
tts = gtts.gTTS(text=text, lang=lang.detect(text)[0]) #, lang='en'
filename = 'tts.temp.mp3' filename = 'tts.temp.mp3'
tts.save(filename) tts.save(filename)
playsound.playsound(filename) playsound.playsound(filename)
os.remove(filename) os.remove(filename)