Spaces:
Runtime error
Runtime error
fuck wit ai google my friend now
Browse files- app.py +2 -2
- requirements.txt +2 -1
- routes/__init__.py +2 -2
- routes/{witaiApi β recognizeApi}/__init__.py +0 -0
- routes/{witaiApi β recognizeApi}/__pycache__/__init__.cpython-310.pyc +0 -0
- routes/{witaiApi β recognizeApi}/__pycache__/recognizeVoice.cpython-310.pyc +0 -0
- routes/{witaiApi β recognizeApi}/recognizeVoice.py +22 -26
app.py
CHANGED
|
@@ -8,7 +8,7 @@ from routes import *
|
|
| 8 |
|
| 9 |
#initing
|
| 10 |
app = Flask(__name__)
|
| 11 |
-
VERSION = '1.0
|
| 12 |
app.config['JSON_AS_ASCII'] = False
|
| 13 |
limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["5/minute"], storage_uri="memory://",)
|
| 14 |
|
|
@@ -63,7 +63,7 @@ def systemInfo(): return siteRoutes.systemInfo()
|
|
| 63 |
###############
|
| 64 |
#RECOGNIZE API
|
| 65 |
@app.route('/recognize/api/v1/voice', methods=['GET', 'POST'])
|
| 66 |
-
def recognizeVoice(): return
|
| 67 |
|
| 68 |
###############
|
| 69 |
#YT SOUND API
|
|
|
|
| 8 |
|
| 9 |
#initing
|
| 10 |
app = Flask(__name__)
|
| 11 |
+
VERSION = '1.0 build81'
|
| 12 |
app.config['JSON_AS_ASCII'] = False
|
| 13 |
limiter = Limiter(app=app, key_func=get_remote_address, default_limits=["5/minute"], storage_uri="memory://",)
|
| 14 |
|
|
|
|
| 63 |
###############
|
| 64 |
#RECOGNIZE API
|
| 65 |
@app.route('/recognize/api/v1/voice', methods=['GET', 'POST'])
|
| 66 |
+
def recognizeVoice(): return recognizeApi.recognizeVoice(request)
|
| 67 |
|
| 68 |
###############
|
| 69 |
#YT SOUND API
|
requirements.txt
CHANGED
|
@@ -6,4 +6,5 @@ urllib3
|
|
| 6 |
requests
|
| 7 |
py-cpuinfo
|
| 8 |
ffmpeg-python
|
| 9 |
-
flask_limiter
|
|
|
|
|
|
| 6 |
requests
|
| 7 |
py-cpuinfo
|
| 8 |
ffmpeg-python
|
| 9 |
+
flask_limiter
|
| 10 |
+
SpeechRecognition
|
routes/__init__.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from .ytApi import *
|
| 2 |
from .osuApi import *
|
| 3 |
from .helpers import *
|
| 4 |
-
from .
|
| 5 |
-
from .
|
|
|
|
| 1 |
from .ytApi import *
|
| 2 |
from .osuApi import *
|
| 3 |
from .helpers import *
|
| 4 |
+
from .siteRoutes import *
|
| 5 |
+
from .recognizeApi import *
|
routes/{witaiApi β recognizeApi}/__init__.py
RENAMED
|
File without changes
|
routes/{witaiApi β recognizeApi}/__pycache__/__init__.cpython-310.pyc
RENAMED
|
File without changes
|
routes/{witaiApi β recognizeApi}/__pycache__/recognizeVoice.cpython-310.pyc
RENAMED
|
File without changes
|
routes/{witaiApi β recognizeApi}/recognizeVoice.py
RENAMED
|
@@ -3,6 +3,7 @@ import random
|
|
| 3 |
import string
|
| 4 |
import ffmpeg
|
| 5 |
from .. import helpers
|
|
|
|
| 6 |
|
| 7 |
def recognizeVoice(request):
|
| 8 |
try:
|
|
@@ -15,42 +16,37 @@ def recognizeVoice(request):
|
|
| 15 |
else: signature = request.args['signature']
|
| 16 |
except: return {"status": "error", "details": { "error_code": 103, "error_details": "No signature" }}
|
| 17 |
if not helpers.checkSignature(signature): return {"status": "error", "details": { "error_code": 105, "error_details": "Invalid signature" }}
|
| 18 |
-
try:
|
| 19 |
-
if request.method == 'POST': extendInfo = request.form['extendInfo']
|
| 20 |
-
else: extendInfo = request.args['extendInfo']
|
| 21 |
-
if extendInfo in ['true','1',1,'yes','y']: extendInfo = True
|
| 22 |
-
else: extendInfo = False
|
| 23 |
-
except: extendInfo = False
|
| 24 |
|
| 25 |
fileId = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
|
| 26 |
fileExt = url[url.rfind('.'):url.rfind('.')+4]
|
| 27 |
-
if
|
| 28 |
-
elif fileExt == ".mp3": fileHeader = {'Content-Type': 'audio/mpeg3'}
|
| 29 |
-
elif fileExt == ".ogg": fileHeader = {'Content-Type': 'audio/ogg'}
|
| 30 |
-
elif fileExt == '.aac': fileHeader = {'Content-Type': 'audio/wav'}
|
| 31 |
else: return {"status": "error", "details": { "error_code": 111, "error_details": "Wrong file format (only ogg, wav, mp3)" }}
|
| 32 |
|
|
|
|
|
|
|
| 33 |
config = helpers.configFile()
|
| 34 |
|
| 35 |
wget.download(url, f"{config['temp-path']}/{fileId}{fileExt}")
|
| 36 |
-
|
| 37 |
-
if fileExt == ".aac":
|
| 38 |
audio_input = ffmpeg.input(f"{config['temp-path']}/{fileId}{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}.
|
| 43 |
-
with open(f"{config['temp-path']}/{fileId}{fileExt}", 'rb') as f:
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
try:
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
| 3 |
import string
|
| 4 |
import ffmpeg
|
| 5 |
from .. import helpers
|
| 6 |
+
import speech_recognition as sr
|
| 7 |
|
| 8 |
def recognizeVoice(request):
|
| 9 |
try:
|
|
|
|
| 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 |
|
| 20 |
fileId = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(16))
|
| 21 |
fileExt = url[url.rfind('.'):url.rfind('.')+4]
|
| 22 |
+
if fileExt in [".wav",".mp3",".ogg",'.aac']: pass
|
|
|
|
|
|
|
|
|
|
| 23 |
else: return {"status": "error", "details": { "error_code": 111, "error_details": "Wrong file format (only ogg, wav, mp3)" }}
|
| 24 |
|
| 25 |
+
r = sr.Recognizer()
|
| 26 |
+
|
| 27 |
config = helpers.configFile()
|
| 28 |
|
| 29 |
wget.download(url, f"{config['temp-path']}/{fileId}{fileExt}")
|
| 30 |
+
if fileExt != ".wav":
|
|
|
|
| 31 |
audio_input = ffmpeg.input(f"{config['temp-path']}/{fileId}{fileExt}")
|
| 32 |
+
oldFE = fileExt
|
| 33 |
fileExt = ".wav"
|
| 34 |
audio_output = ffmpeg.output(audio_input.audio, f"{config['temp-path']}/{fileId}{fileExt}")
|
| 35 |
ffmpeg.run(audio_output)
|
| 36 |
+
helpers.deleteAudio(f"temp/{fileId}.{oldFE}")
|
| 37 |
+
#with open(f"{config['temp-path']}/{fileId}{fileExt}", 'rb') as f:
|
| 38 |
+
rawSource = sr.AudioFile(f"{config['temp-path']}/{fileId}{fileExt}")
|
| 39 |
+
with rawSource as source:
|
| 40 |
+
r.adjust_for_ambient_noise(source)
|
| 41 |
+
audio = r.record(source)
|
| 42 |
+
|
| 43 |
+
try: googleText = r.recognize_google(audio)
|
| 44 |
+
except: googleText = ""
|
| 45 |
+
|
| 46 |
+
# at now here's no keys :(
|
| 47 |
+
#try: houndifyText = r.recognize_houndify(audio)
|
| 48 |
+
#except: houndifyText = ""
|
| 49 |
|
| 50 |
+
helpers.deleteAudio(f"temp/{fileId}{fileExt}")
|
| 51 |
+
|
| 52 |
+
return {"status": "pass", "result": {"google": googleText, "houndify": "NOT-WORKING"}}
|