Hi,
I have been trying to work on API. I’m using DeepSpeech 0.9.3 version. Here is my python code…
import subprocess
import uuid
import scipy.io.wavfile
from deepspeech import Model
from flask import Flask
from flask import jsonify
from flask import request
from flask_cors import CORS, cross_origin
#BEAM_WIDTH = 1024
#LM_WEIGHT = 0.75
#VALID_WORD_COUNT_WEIGHT = 1.85
#N_FEATURES = 26
#N_CONTEXT = 9
#MODEL_FILE = ‘C:\Users\Chaitanya15\speechdeep\output_graph.pbmm’
#ALPHABET_FILE = ‘models/alphabet.txt’
#LANGUAGE_MODEL = ‘C:\Users\Chaitanya15\speechdeep\kenlm.scorer’
#TRIE_FILE = ‘models/trie’
ds = Model(‘C:\Users\Chaitanya15\speechdeep\output_graph.pbmm’)
ds.enableExternalScorer(‘C:\Users\Chaitanya15\speechdeep\kenlm.scorer’)
#ds.setScorerAlphaBeta(args.lm_alpha, args.lm_beta)
app = Flask(name)
cors = CORS(app)
app.config[‘CORS_HEADERS’] = ‘Content-Type’
@app.route(’/’, methods=[‘POST’])
@cross_origin()
def post():
fileName = ‘file_’+str(uuid.uuid4())+’.wav’
with open(fileName, “wb”) as vid:
vid.write(request.data)
audio = scipy.io.wavfile.read(fileName)
processed_data = ds.stt(audio)
# proc = subprocess.Popen(
# "deepspeech --model models/output_graph.pbmm --alphabet models/alphabet.txt --lm models/lm.binary --trie models/trie --audio fileName",
# shell=True, stdout=subprocess.PIPE, )
# output = proc.communicate()[0]
# print(output)
print(processed_data)
return jsonify(
username=processed_data
)
@app.route(’/file’, methods=[‘POST’])
@cross_origin()
def post1():
fileName = ‘file_’+str(uuid.uuid4())+’.wav’
with open(fileName, “wb”) as vid:
vid.write(request.data)
audio= scipy.io.wavfile.read(fileName)
processed_data = ds.stt(audio)
# proc = subprocess.Popen(
# "deepspeech --model models/output_graph.pbmm --alphabet models/alphabet.txt --lm models/lm.binary --trie models/trie --audio fileName",
# shell=True, stdout=subprocess.PIPE, )
# output = proc.communicate()[0]
print(processed_data)
return jsonify(
username=processed_data
)
if name == ‘main’:
app.run(host=‘0.0.0.0’, port=80,debug=True)
After executing this and providing audio in frontend it gives me an error.
“”"""""""""""""""""""""""""""
127.0.0.1 - - [07/Jul/2021 01:06:00] “OPTIONS /file HTTP/1.1” 200 -
Exception happened during processing of request from (‘127.0.0.1’, 64457)
TypeError: only size-1 arrays can be converted to Python scalars
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug_init_.py”, line 309, in debug_application
app_iter = self.app(environ, start_response)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 2088, in call
return self.wsgi_app(environ, start_response)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 2073, in wsgi_app
response = self.handle_exception(e)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask_cors\extension.py”, line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 2070, in wsgi_app
response = self.full_dispatch_request()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 1515, in full_dispatch_request
rv = self.handle_user_exception(e)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask_cors\extension.py”, line 165, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 1513, in full_dispatch_request
rv = self.dispatch_request()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask\app.py”, line 1499, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\flask_cors\decorator.py”, line 128, in wrapped_function
resp = make_response(f(*args, **kwargs))
File “C:\Users\Chaitanya15\speechdeep\backend\server_test.py”, line 58, in post1
processed_data = ds.stt(audio)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\deepspeech_init_.py”, line 162, in stt
return deepspeech.impl.SpeechToText(self._impl, audio_buffer)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\deepspeech\impl.py”, line 175, in SpeechToText
return _impl.SpeechToText(aCtx, aBuffer)
ValueError: setting an array element with a sequence.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\serving.py”, line 319, in run_wsgi
execute(self.server.app)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\serving.py”, line 310, in execute
for data in application_iter:
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug_init_.py”, line 319, in debug_application
ignore_system_exceptions=True,
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 182, in get_current_traceback
tb.filter_hidden_frames()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 248, in filter_hidden_frames
group.filter_hidden_frames()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 388, in filter_hidden_frames
elif self.frames[-1] in new_frames:
IndexError: list index out of range
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\socketserver.py”, line 650, in process_request_thread
self.finish_request(request, client_address)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\socketserver.py”, line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\socketserver.py”, line 720, in init
self.handle()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\serving.py”, line 342, in handle
BaseHTTPRequestHandler.handle(self)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\http\server.py”, line 426, in handle
self.handle_one_request()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\serving.py”, line 374, in handle_one_request
self.run_wsgi()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\serving.py”, line 327, in run_wsgi
traceback = get_current_traceback(ignore_system_exceptions=True)
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 182, in get_current_traceback
tb.filter_hidden_frames()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 248, in filter_hidden_frames
group.filter_hidden_frames()
File “C:\Users\Chaitanya15\anaconda3\envs\speechdeep\lib\site-packages\werkzeug\debug\tbtools.py”, line 388, in filter_hidden_frames
elif self.frames[-1] in new_frames:
IndexError: list index out of range
what changes should I do to work this on, please help me with this.