Compare commits

...

3 commits

Author SHA1 Message Date
4e878b28f3 Merge pull request 'main' (#22) from React-Group/interstellar_ai:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/YasinOnm08/interstellar_ai/pulls/22
2024-09-26 08:57:51 +02:00
Patrick_Pluto
6d03e1fafc fixed stuff? 2024-09-26 08:33:11 +02:00
Patrick_Pluto
42b12f73b4 TTS 2024-09-25 16:34:02 +02:00
4 changed files with 25 additions and 4 deletions

View file

@ -6,6 +6,7 @@ from ai import AI
from db import DB from db import DB
from weather import Weather from weather import Weather
from voice import VoiceRecognition from voice import VoiceRecognition
from tts import TTS
class API: class API:
@ -17,6 +18,7 @@ class API:
self.db = DB() self.db = DB()
self.weather = Weather() self.weather = Weather()
self.voice = VoiceRecognition() self.voice = VoiceRecognition()
self.tts = TTS()
self.db.load_database() self.db.load_database()
self.ai_response_lock = threading.Lock() self.ai_response_lock = threading.Lock()
CORS(self.app) CORS(self.app)
@ -98,7 +100,7 @@ class API:
@self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST']) @self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
def voice_recognition(): def voice_recognition():
recognition_type = request.args.get('type') recognition_type = request.args.get('type')
audio = request.args.get('audio_data') audio = request.files['audio']
option = request.args.get('option') option = request.args.get('option')
if recognition_type == "basic": if recognition_type == "basic":
return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)}) return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)})
@ -113,6 +115,11 @@ class API:
self.app.run(debug=True, host='0.0.0.0', port=5000) 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 = API()
api.run() api.run()

View file

@ -10,4 +10,6 @@ PocketSphinx
google-cloud-speech google-cloud-speech
google-generativeai google-generativeai
python-weather python-weather
pycouchdb pycouchdb
pyttsx3
pip-licenses

10
py/tts.py Normal file
View file

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

View file

@ -6,8 +6,10 @@ class VoiceRecognition:
def basic_recognition(audio, option): def basic_recognition(audio, option):
r = sr.Recognizer() r = sr.Recognizer()
if option == "online": if option == "online":
return r.recognize_google_cloud(audio) with audio as source:
return r.recognize_google_cloud(source)
elif option == "offline": elif option == "offline":
return r.recognize_sphinx(audio) with audio as source:
return r.recognize_sphinx(source)
return False return False