woolbot commited on
Commit
20130a8
1 Parent(s): f626f92
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  wget
2
  flask
 
3
  numpy
4
  psutil
5
  yt_dlp
 
1
  wget
2
  flask
3
+ keras
4
  numpy
5
  psutil
6
  yt_dlp
routes/aminoOSRapi/recognizeVoice.py DELETED
@@ -1,58 +0,0 @@
1
- import wget
2
- import random
3
- import string
4
- import ffmpeg
5
- from .. import helpers
6
- import speech_recognition as sr
7
-
8
- def recognizeVoice(request):
9
- try:
10
- if request.method == 'POST': url = request.form['url']
11
- else: url = request.args['url']
12
- if url.strip() in ['', None]: raise Exception()
13
- except: return {"status": "error", "details": { "error_code": 101, "error_details": "No link provided" }}
14
- try:
15
- if request.method == 'POST': signature = request.form['signature']
16
- else: signature = request.args['signature']
17
- except: return {"status": "error", "details": { "error_code": 103, "error_details": "No signature" }}
18
- if not helpers.checkSignature(signature): return {"status": "error", "details": { "error_code": 105, "error_details": "Invalid signature" }}
19
- try:
20
- if request.method == 'POST': lang = request.form['lang']
21
- else: lang = request.args['lang']
22
- if lang.lower() in ['en','en-us']: lang = 'en-US'
23
- elif lang.lower() in ['ru','ru-ru']: lang = 'ru-RU'
24
- except: lang = "en-US"
25
-
26
- fileId = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
27
- fileExt = url[url.rfind('.'):url.rfind('.')+4]
28
- if fileExt in [".wav",".mp3",".ogg",'.aac']: pass
29
- else: return {"status": "error", "details": { "error_code": 111, "error_details": "Wrong file format (only ogg, wav, mp3)" }}
30
-
31
- r = sr.Recognizer()
32
-
33
- config = helpers.configFile()
34
-
35
- wget.download(url, f"{config['temp-path']}/{fileId}{fileExt}")
36
- if fileExt != ".wav":
37
- audio_input = ffmpeg.input(f"{config['temp-path']}/{fileId}{fileExt}")
38
- oldFE = fileExt
39
- fileExt = ".wav"
40
- audio_output = ffmpeg.output(audio_input.audio, f"{config['temp-path']}/{fileId}{fileExt}")
41
- ffmpeg.run(audio_output)
42
- helpers.deleteAudio(f"temp/{fileId}.{oldFE}")
43
-
44
- rawSource = sr.AudioFile(f"{config['temp-path']}/{fileId}{fileExt}")
45
- with rawSource as source:
46
- r.adjust_for_ambient_noise(source)
47
- audio = r.record(source)
48
-
49
- try: googleText = r.recognize_google(audio, language=lang)
50
- except: googleText = ""
51
-
52
- # at now here's no keys :(
53
- #try: houndifyText = r.recognize_houndify(audio)
54
- #except: houndifyText = ""
55
-
56
- helpers.deleteAudio(f"temp/{fileId}{fileExt}")
57
-
58
- return {"status": "pass", "result": {"google": googleText, "houndify": "NOT-WORKING"}}