Код: Выделить всё
@app.websocket("/proces")
async def process_file(websocket:WebSocket):
await websocket.accept()
data=await websocket.receive_text()
data=json.loads(data)
print(data)
await websocket.send_text(f"recieved{data}")
logger=MyBarLogger(websocket)
audio=media_clip_audio(f"uploaded_files/{data['file_name']}",data["start_time"],data["end_time"],logger)
Код: Выделить всё
class MyBarLogger(ProgressBarLogger):
def __init__(self,websocket:WebSocket):
super().__init__()
self.wbs=websocket
async def sc(self,p):
print("trying to send a message")
await (self.wbs).send_text({"data":p})
def bars_callback(self, bar, attr, value,old_value=None):
# Every time the logger progress is updated, this function is called
self.percentage = (value / self.bars[bar]['total']) * 100
global progress
progress=self.percentage
asyncio.get_event_loop().run_until_complete(self.sc(self.percentage))
print("prg",progress)
Код: Выделить всё
def media_clip_audio(media_path, start_time, end_time,log):
clip =VideoFileClip(media_path)
cut_clip = clip.subclip(start_time, end_time)
audio_clip = cut_clip.audio
audio_name = "tsstss.wav"
audio_clip.write_audiofile(audio_name,logger=log)
Код: Выделить всё
function process(){
var info={
"start_time":startTime,
"end_time":endTime,
"file_name":uploadedFilename};
let infostring=JSON.stringify(info);
console.log("serial",infostring);
const ws= new WebSocket('ws://127.0.0.1:8000/proces');
ws.addEventListener('open',(event)=>{
console.log("connected");
console.log("info",info);
ws.send(infostring);
});
ws.onmessage= function(event){
console.log(event.data);
};
await send(message)
Файл «/home/my_mcap_env/lib/python3.10/site-packages/uvicorn/protocols/websockets/websockets_impl.py», строка 359, в asgi_send
raise RuntimeError(msg % message_type)
RuntimeError: неожиданное сообщение ASGI «websocket.send» после отправки «websocket.close» или уже завершенный ответ
почему возникла эта проблема и как ее устранить решить это?
Подробнее здесь: https://stackoverflow.com/questions/785 ... -websocket