diff --git a/py/api.py b/py/api.py index 01e99b1..5fba195 100644 --- a/py/api.py +++ b/py/api.py @@ -6,6 +6,7 @@ from ai import AI from db import DB from weather import Weather from voice import VoiceRecognition +from tts import TTS class API: @@ -17,6 +18,7 @@ class API: self.db = DB() self.weather = Weather() self.voice = VoiceRecognition() + self.tts = TTS() self.db.load_database() self.ai_response_lock = threading.Lock() CORS(self.app) @@ -113,6 +115,11 @@ class API: self.app.run(debug=True, host='0.0.0.0', port=5000) + @self.app.route('/interstellar_ai/api/tts', methods=['POST']) + def tts(): + text = request.args.get('text') + return jsonify({'status': 200, 'response': self.tts.gen_tts(text)}) + api = API() api.run() diff --git a/py/requirements.txt b/py/requirements.txt index 6cd3616..47523c5 100644 --- a/py/requirements.txt +++ b/py/requirements.txt @@ -10,4 +10,6 @@ PocketSphinx google-cloud-speech google-generativeai python-weather -pycouchdb \ No newline at end of file +pycouchdb +pyttsx3 +pip-licenses \ No newline at end of file diff --git a/py/tts.py b/py/tts.py new file mode 100644 index 0000000..93f7fa4 --- /dev/null +++ b/py/tts.py @@ -0,0 +1,10 @@ +import pyttsx3 + + +class TTS: + @staticmethod + def gen_tts(text): + engine = pyttsx3.init() + engine.setProperty('rate', 70) + engine.say(text) + engine.runAndWait()