From f1df6b24edf64efad9cd649f66e71415259a56e3 Mon Sep 17 00:00:00 2001 From: Khyretos Date: Sun, 31 Dec 2023 22:12:52 +0100 Subject: [PATCH] language detection, twitch funcitonality updates --- package.json | 2 + src/backend/loquendoBot_backend.py | 61 ++- src/css/chat.css | 29 ++ src/css/tabs.css | 21 - src/index.html | 97 +++-- src/js/auth.js | 30 +- src/js/backend.js | 140 ++++++- src/js/languages.js | 646 ++++++++++++++--------------- src/js/messageTemplates.js | 4 +- src/js/renderer.js | 83 +++- src/js/settings.js | 99 ++++- src/js/sound.js | 42 +- src/js/twitch.js | 316 +++++++++----- src/main.js | 22 +- 14 files changed, 944 insertions(+), 648 deletions(-) diff --git a/package.json b/package.json index 7e63f61..5feb6a2 100644 --- a/package.json +++ b/package.json @@ -21,12 +21,14 @@ "electron-squirrel-startup": "^1.0.0", "emoji-picker-element": "^1.21.0", "express": "^4.18.2", + "flag-icons": "^7.1.0", "ini": "^2.0.0", "kill-process-by-name": "^1.0.5", "node-google-tts-api": "^1.1.1", "querystring": "^0.2.1", "socket.io": "^4.7.1", "socket.io-client": "^4.7.1", + "sockette": "^2.0.6", "tmi.js": "^1.8.5", "url": "^0.11.1", "winston": "^3.10.0", diff --git a/src/backend/loquendoBot_backend.py b/src/backend/loquendoBot_backend.py index 43e472d..919ff58 100644 --- a/src/backend/loquendoBot_backend.py +++ b/src/backend/loquendoBot_backend.py @@ -1,4 +1,3 @@ -# from wsgiref.simple_server import WSGIServer from flask import Flask, Response, jsonify, request import gevent @@ -201,14 +200,6 @@ def stop_recording(): return Response("Speech recognition stopped", status=200) -# @app.before_request -# def custom_warning(): -# if environment == "dev": -# print( -# # "Running in internal development environment. This server is not for production use." -# ) - - @app.route("/terminate", methods=["GET"]) def terminate_processes(): shutdown_server() @@ -222,25 +213,37 @@ def shutdown_server(): func() -# @app.route("/detect", methods=["POST"]) -# def server_status(): -# try: -# request_data = request.json -# message = request_data.get("message", "") -# confidence_values = detector.compute_language_confidence_values(message) -# for language, value in confidence_values: -# print(f"{language.name}: {value:.2f}") -# message = request_data.get("message", "") -# except Exception as e: -# return jsonify({"error": "An error occurred"}), 500 -# return jsonify({"message": "Audio triggered"}), 200 - - @app.route("/status", methods=["GET"]) def server_status(): return jsonify({"status": "server is running"}) +@app.route("/detect", methods=["POST"]) +def get_language(): + try: + request_data = request.json + message = request_data.get("message", "") + lang = LanguageDetection().predict_lang(message) + except Exception as e: + return jsonify({"error": "An error occurred"}), 500 + return jsonify({"languages": lang}), 200 + + +@app.route("/translate", methods=["POST"]) +def get_translation(): + try: + settings.read(settingsPath) + request_data = request.json + message = request_data.get("message", "") + detectedLanguage = request_data.get("language", "") + translated = MyMemoryTranslator( + source=detectedLanguage, target=settings["LANGUAGE"]["TRANSLATE_TO"] + ).translate(message) + except Exception as e: + return jsonify({"error": e}), 500 + return jsonify({"translation": translated}), 200 + + @app.route("/audio", methods=["POST"]) def trigger_backend_event(): try: @@ -255,7 +258,7 @@ def trigger_backend_event(): count = request_data.get("count") text_to_speech_service.say(filteredMessage, voice, count) except Exception as e: - return jsonify({"error": "An error occurred"}), 500 + return jsonify({"error": e}), 500 return jsonify({"message": "Audio triggered"}), 200 @@ -265,18 +268,10 @@ def get_voices(): voices = text_to_speech_service.voices() return jsonify({"voices": voices}), 200 except Exception as e: - return jsonify({"error": "An error occurred"}), 500 + return jsonify({"error": e}), 500 if __name__ == "__main__": - # LANGUAGE = LanguageDetection() - # lang = LANGUAGE.predict_lang("hola cómo estás") - # print(lang) - # text = "Keep it up. You are awesome" - # translated = MyMemoryTranslator( - # source="english", target="spanish latin america" - # ).translate(text) - # print(translated) if len(sys.argv) > 1: settings.read(settingsPath) port = int(settings["GENERAL"]["PORT"]) diff --git a/src/css/chat.css b/src/css/chat.css index 53042b2..bd32a5b 100644 --- a/src/css/chat.css +++ b/src/css/chat.css @@ -513,3 +513,32 @@ h1 { position: absolute; z-index: 1; } + +.fi { + position: relative; + z-index: 5; + top: 45px; + left: 20px; + border-radius: 50%; +} + +.translation-header { + background-color: var(--main-color4); + border-radius: 5px; + width: fit-content; + padding: 5px; + margin: 10px 0px 5px -5px; + position: relative; +} + +.translation-message { + position: relative; + margin: 20px 0px 0px 0px; +} + +.translation-icon { + position: relative; + padding: 0px 0px 0px 0px; + margin: -45px 0px 0px -40px; + top: -15px; +} diff --git a/src/css/tabs.css b/src/css/tabs.css index 8e71345..26fef88 100644 --- a/src/css/tabs.css +++ b/src/css/tabs.css @@ -395,27 +395,6 @@ input[type='lol'] { z-index: 999; } -/* .tooltip .tooltiptext { - width: 120px; - background-color: black; - color: #fff; - text-align: center; - border-radius: 6px; - padding: 5px 0; -} - -.tooltip .tooltiptext::after { - content: ""; - margin-left: -5px; - border-width: 5px; - border-style: solid; - border-color: black transparent transparent transparent; -} - -.tooltip:hover .tooltiptext { - visibility: visible; -} */ - div[type='text']:disabled { background: #4b4b4b; display: none; diff --git a/src/index.html b/src/index.html index cbf6544..d187d26 100644 --- a/src/index.html +++ b/src/index.html @@ -26,6 +26,7 @@ /> + @@ -151,6 +152,15 @@ tip="Port to use to host additional services" > +
+
Open Settings file
+ + +
@@ -160,22 +170,14 @@
Enable TTS
-
+ -
-
Default TTS language
- -
-
+ -
-
2nd TTS language
- -
TTS Output Device
@@ -247,16 +249,25 @@
Translate chat messages to
- +
-
Broadcast translation
- - +
Broadcast translation to chat
+ +
-
Output to TTS service
- +
Output translation to TTS
+ + +
+
+
Default TTS service language
+ +
+
+
2nd TTS service language
+
@@ -267,7 +278,7 @@
Enable notification sounds
-
+
Notification sounds Output Device
-
Notification Volume
@@ -304,6 +314,20 @@
Enable Twitch
+
+
Oauth Token
+ + + +
Channel Name
@@ -313,20 +337,6 @@ tip="The channel you want to connect to" >
-
-
Oauth Token
- - - -
Test credentials
@@ -336,17 +346,6 @@ tip="Test Twitch credentials" >
-
-
Get Twitch emotes
- - -
@@ -356,7 +355,7 @@
Enable Modules
-
+ -
+
-
+
-
+