coqui-ai / xtts-streaming-server

Mozilla Public License 2.0
295 stars 88 forks source link

asyncio.exceptions.CancelledError: Cancelled by cancel scope 7ff72233f610 #18

Open sunbeibei-hub opened 9 months ago

sunbeibei-hub commented 9 months ago
@app.post("/api/xtts_stream")
def gpt_xtts_stream(inputs: xtts_stream_inputs):
    try:
        speaker["text"] = inputs.text
        speaker['language'] = inputs.language
        speaker['stream_chunk_size'] = inputs.stream_chunk_size

        res = requests.post(
            f"http://0.0.0.0:8004/tts_stream",
            json=speaker,
            stream=True,
        )

        def iterms_gene(res):
            if res.status_code != 200:
                print("Error:", res.text)
                sys.exit(1)
            first = True
            for chunk in res.iter_content(chunk_size=512):
                if first:
                    first = False
                if chunk:
                    yield chunk
        # 返回音频流文件
        return StreamingResponse(iterms_gene(res), media_type="audio/wav")
    except Exception as e:
        logging.error(f"Error: {e}")
        return {"error": str(e)}

i want to use main.py in /tts_stream, so up.
but, i get down error:

ERROR: Exception in ASGI application Traceback (most recent call last): File "/home/search/miniconda3/envs/XTTS/lib/python3.9/site-packages/starlette/responses.py", line 259, in call await wrap(partial(self.listen_for_disconnect, receive)) File "/home/search/miniconda3/envs/XTTS/lib/python3.9/site-packages/starlette/responses.py", line 255, in wrap await func() File "/home/search/miniconda3/envs/XTTS/lib/python3.9/site-packages/starlette/responses.py", line 232, in listen_for_disconnect message = await receive() File "/home/search/miniconda3/envs/XTTS/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 538, in receive await self.message_event.wait() File "/home/search/miniconda3/envs/XTTS/lib/python3.9/asyncio/locks.py", line 226, in wait await fut asyncio.exceptions.CancelledError: Cancelled by cancel scope 7ff72233f610

During handling of the above exception, another exception occurred:

main.py don`t change!

rvuyyuru2 commented 9 months ago

same issue what to do how to fix

henvu50 commented 8 months ago

same issue here as well

javi22020 commented 6 months ago

Same problem