diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/jarvis-server-v2.iml b/.idea/jarvis-server-v2.iml new file mode 100644 index 0000000..dc6ae03 --- /dev/null +++ b/.idea/jarvis-server-v2.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..7ca03e3 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7e98294 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..fca8192 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM ubuntu:21.04 + +ENV DEBIAN_FRONTEND=noninteractive +ENV ENV_STATUS=${NODE_ENV:-production} + +# For suport set local time zone. +RUN apt-get update -y && apt-get upgrade -y + +WORKDIR /jarvis + +RUN apt install python3.9 python3-pip python3.9-dev python3.9-distutils python3-fann2 libfann-dev swig git python3-levenshtein curl -y + +RUN git clone --branch $(curl --silent "https://api.github.com/repos/m4th1eu/jarvis-server/releases/latest" | grep -Po '"tag_name": "\K.*?(?=")') --progress --verbose https://github.com/M4TH1EU/jarvis-server.git . + +RUN python3 -m pip install -r requirements.txt + +RUN apt-get clean -y + +EXPOSE 5000 + +COPY start.sh /jarvis/ + +RUN chmod +x start.sh + +CMD "./start.sh" \ No newline at end of file diff --git a/api.py b/api.py new file mode 100644 index 0000000..3874306 --- /dev/null +++ b/api.py @@ -0,0 +1,70 @@ +import json +import tempfile + +import requests +from flask import request, Flask + +app = Flask(__name__) + + +# .WAV (i.e.) FILE REQUEST +@app.route("/process_audio_request_file", methods=['POST']) +def process_audio_request_android(): + print("[" + request.remote_addr + "] - New STT request") + + audio_temp_file = tempfile.NamedTemporaryFile(prefix='jarvis-audio_', suffix='_client') + audio_temp_file.write(request.data) + print(audio_temp_file.name) + + return {"transcription": text_recognition_whisperasr(audio_temp_file.name), "answer": "WIP"} + + +# send request to whisper-asr server (docker) +def text_recognition_whisperasr(audio_file): + headers = { + 'accept': 'application/json', + # 'Content-Type': 'multipart/form-data', + } + + params = { + 'task': 'transcribe', + # TODO: add to config + 'language': 'fr', + 'output': 'json', + } + + files = { + 'audio_file': open(audio_file, 'rb'), + } + + # TODO: add to config + response = requests.post('http://192.168.1.208:9000/asr', params=params, headers=headers, files=files) + return json.loads(response.text)['text'] + + +# NOT IMPLEMENTED RIGHT NOW / to use with local whisper cpp (cpu) +""" +def local_recognition(audio_file, time_of_request): + path = os.path.dirname(get_path_file.__file__) + + print("Loading model and recognition") + model = path + "/whisper/models/" + "ggml-small.bin" + os.system(path + "/whisper/main -l fr -t 8 -m " + model + " -f " + audio_file + " -otxt") # + "> /dev/null 2>&1") + + output = open(audio_file + ".txt").read() + + # time_of_resolution = time.perf_counter() + # print(output + f" - {time_of_resolution - time_of_request:0.4f} seconds") + + return jsonify(transcription=output, time=5, answer="WIP...") +""" + + +def start_server(): + app.config['JSON_AS_ASCII'] = False + # TODO: add to config + app.run(port=5000, debug=False, host='0.0.0.0', threaded=True) + + +if __name__ == '__main__': + start_server() diff --git a/test_whisper.py b/test_whisper.py new file mode 100644 index 0000000..748ce30 --- /dev/null +++ b/test_whisper.py @@ -0,0 +1,21 @@ +# to install whisper : +# pip install git+https://github.com/openai/whisper.git + +import whisper + +model = whisper.load_model("tiny") +print("MODEL LOADED") + +# load audio and pad/trim it to fit 30 seconds +audio = whisper.load_audio("/home/mathieu/Dev/PYTHON/newjarvis-server/out.wav") +audio = whisper.pad_or_trim(audio) + +# make log-Mel spectrogram and move to the same device as the model +mel = whisper.log_mel_spectrogram(audio).to(model.device) + +# decode the audio +options = whisper.DecodingOptions(fp16=False) +result = whisper.decode(model, mel, options) + +# print the recognized text +print(result.text) \ No newline at end of file diff --git a/todo_ideas_google.txt b/todo_ideas_google.txt new file mode 100644 index 0000000..6ee9a45 --- /dev/null +++ b/todo_ideas_google.txt @@ -0,0 +1,47 @@ +Ok Google souviens-toi que j’ai mis les clés [ou n’importe quel objet] à l’entrée [ou n’importe quel autre endroit] +Ok Google, où sont mes clés ? + + + +Ok Google, où se trouve mon smartphone / iPhone ? + + + +Ok Google, rappelle-moi de rappeler ma mère à 18 heures + + + +Ok Google, comment dit-on merci en Chinois mandarin ? +Ok Google, traduis “je t’aime” en japonais + + +Ok Google, appairage Bluetooth +Ok Google, déconnecte le Bluetooth + + +Ok Google, mets le minuteur sur 5 minutes +Ok Google, combien de temps reste-t-il sur le minuteur ? +Ok Google, arrête/annule le minuteur +Ok Google, stop (lorsque le minuteur sonne) + + + +Ok Google, mets une alarme à [heure] +Ok Google, annule l’alarme + + + +Ok Google, quelle est la définition de [mot] + + + +Ok Google, raconte-moi quelque chose d’intéressant + + + +Ok Google, parle à Akinator + + + +Ok Google, raconte-moi une histoire +