From 42b12f73b4aec70fe0df5e8a97299dede262ce6e Mon Sep 17 00:00:00 2001
From: Patrick_Pluto <patrick_pluto@noreply.codeberg.org>
Date: Wed, 25 Sep 2024 16:34:02 +0200
Subject: [PATCH 1/2] TTS

---
 py/api.py           |  7 +++++++
 py/requirements.txt |  4 +++-
 py/tts.py           | 10 ++++++++++
 3 files changed, 20 insertions(+), 1 deletion(-)
 create mode 100644 py/tts.py

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()

From 6d03e1fafcd0feff0bc1f0e2123eaca9f27410a7 Mon Sep 17 00:00:00 2001
From: Patrick_Pluto <patrick_pluto@noreply.codeberg.org>
Date: Thu, 26 Sep 2024 08:33:11 +0200
Subject: [PATCH 2/2] fixed stuff?

---
 py/api.py   | 2 +-
 py/voice.py | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/py/api.py b/py/api.py
index 5fba195..1c4e089 100644
--- a/py/api.py
+++ b/py/api.py
@@ -100,7 +100,7 @@ class API:
         @self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
         def voice_recognition():
             recognition_type = request.args.get('type')
-            audio = request.args.get('audio_data')
+            audio = request.files['audio']
             option = request.args.get('option')
             if recognition_type == "basic":
                 return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)})
diff --git a/py/voice.py b/py/voice.py
index 7ead0a5..d589eab 100644
--- a/py/voice.py
+++ b/py/voice.py
@@ -6,8 +6,10 @@ class VoiceRecognition:
     def basic_recognition(audio, option):
         r = sr.Recognizer()
         if option == "online":
-            return r.recognize_google_cloud(audio)
+            with audio as source:
+                return r.recognize_google_cloud(source)
         elif option == "offline":
-            return r.recognize_sphinx(audio)
+            with audio as source:
+                return r.recognize_sphinx(source)
 
         return False