I need help with basic stuff again… I think the question is essentially, why can I not send and receive JSON?
ITT client-side error
192.168.2.250:54636 - "POST /itt HTTP/1.1" 422 Unprocessable Entity
ITT server-side error
{"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]}
# image-to-text client
response = requests.post(url, json=json.dumps(mesg.dict()), stream=True, headers={"Content-Type": "application/json"})#, headers=headers)
# image-to-text proxy
@app.post("/itt")
#async def itt(context:UserImageContext)->StreamingResponse:
async def itt(data:Dict)->StreamingResponse:
""" (b64-encoded) image to text """
print('itt', file=sys.stderr)
context = json.loads(data)
result :AsyncIterator[str] = _itt(client, context) # TODO await ?
return StreamingResponse(result)
the STT error
{"detail":[{"loc":["body"],"msg":"value is not a valid dict","type":"type_error.dict"}]}^CTraceback (most recent call last):
# speech-to-text client
response = requests.post('http://kali.innovanon.com:5002', json=json.dumps(audio_data.tolist()), headers={"Content-Type": "application/json"})
# speech-to-text proxy
@app.post("/stt")
async def stt(data:Dict)->Response:
print('stt', file=sys.stderr)
response = requests.post(host3 , json=data, headers={"Content-Type": "application/json"})
return Response(response.content)
# speech-to-text server
@app.post("/")
async def stt(data:Dict)->Response:
audio_np = np.array(json.loads(data))
result:Dict[str,str] = audio_model.transcribe(audio_np, fp16=torch.cuda.is_available()) # TODO async ?
text:str = result['text'].strip()
print('stt end', file=sys.stderr)
return Response(text)
I think the ones below here are working, but I’m getting an illegal instruction during encoding. Computer unfixably old probably.
# text-to-speech client
response = requests.get(url, params={'prompt':mesg}) # TODO headers ?
print('sent_to_server', file=sys.stderr)
if response.status_code != 200:
print('error', response, file=sys.stderr)
return
print('ok_to_server', file=sys.stderr)
content = json.loads(response.content)
audio:ndarray = np.array(content)
# text-to-speech proxy
@app.get("/tts")
async def tts(prompt:str)->Response:
print('tts', prompt, file=sys.stderr)
response = requests.get(host2, params={'prompt':prompt}) # TODO async ? # TODO headres ?
return Response(response.content)
# text-to-speech server
@app.get("/")
async def tts(prompt:str, name:str="en_speaker_9")->Response:
print('received', file=sys.stderr)
audio_array:ndarray = generate_audio(prompt, history_prompt=name) # TODO no async ?
content = audio_array.tolist()
print('generated', file=sys.stderr)
return Response(json.dumps(audio_array))