mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-14 11:34:43 +08:00
feat(python-subprocess): 尝试字幕显示新解决方案
- 使用 python 子进程解析字幕 - 通过 websocket 通信将字幕传递给软件
This commit is contained in:
66
python-prototype/webscoket.ipynb
Normal file
66
python-prototype/webscoket.ipynb
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "4604aefd",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Received: {\"message\":\"Electron Initialized\"}\n",
|
||||
"Received: {\"command\":\"process_data\",\"payload\":{\"some\":\"data\"}}\n",
|
||||
"Client disconnected\n",
|
||||
"Received: {\"message\":\"Electron Initialized\"}\n",
|
||||
"Received: {\"command\":\"process_data\",\"payload\":{\"some\":\"data\"}}\n",
|
||||
"Client disconnected\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import asyncio\n",
|
||||
"import websockets\n",
|
||||
"import nest_asyncio\n",
|
||||
"\n",
|
||||
"# 应用补丁,允许在 Jupyter 中运行嵌套事件循环\n",
|
||||
"nest_asyncio.apply()\n",
|
||||
"\n",
|
||||
"async def handle_client(websocket, path=\"/\"):\n",
|
||||
" try:\n",
|
||||
" async for message in websocket:\n",
|
||||
" print(f\"Received: {message}\")\n",
|
||||
" await websocket.send(f\"Echo: {message}\")\n",
|
||||
" except websockets.exceptions.ConnectionClosed:\n",
|
||||
" print(\"Client disconnected\")\n",
|
||||
"\n",
|
||||
"start_server = websockets.serve(handle_client, \"localhost\", 8765)\n",
|
||||
"\n",
|
||||
"asyncio.get_event_loop().run_until_complete(start_server)\n",
|
||||
"asyncio.get_event_loop().run_forever()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "mystd",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
Reference in New Issue
Block a user