This commit is contained in:
Mathieu B 2022-11-28 21:56:08 +01:00
parent 6fc362f30d
commit 556b0553e3
10 changed files with 214 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

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

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="Flask">
<option name="enabled" value="true" />
</component>
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.10 (jarvis-server-v2)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
<option name="TEMPLATE_CONFIGURATION" value="Jinja2" />
</component>
</module>

7
.idea/misc.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (jarvis-server-v2)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/jarvis-server-v2.iml" filepath="$PROJECT_DIR$/.idea/jarvis-server-v2.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

25
Dockerfile Normal file
View File

@ -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"

70
api.py Normal file
View File

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

21
test_whisper.py Normal file
View File

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

47
todo_ideas_google.txt Normal file
View File

@ -0,0 +1,47 @@
Ok Google souviens-toi que jai mis les clés [ou nimporte quel objet] à lentrée [ou nimporte 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 taime” 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 lalarme
Ok Google, quelle est la définition de [mot]
Ok Google, raconte-moi quelque chose dintéressant
Ok Google, parle à Akinator
Ok Google, raconte-moi une histoire