mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-11 10:04:47 +08:00
refactor(项目): 尝试 Python 语音识别和内容发送
This commit is contained in:
@@ -11,10 +11,6 @@
|
||||
"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"
|
||||
]
|
||||
}
|
||||
@@ -23,6 +19,7 @@
|
||||
"import asyncio\n",
|
||||
"import websockets\n",
|
||||
"import nest_asyncio\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"# 应用补丁,允许在 Jupyter 中运行嵌套事件循环\n",
|
||||
"nest_asyncio.apply()\n",
|
||||
@@ -31,7 +28,7 @@
|
||||
" try:\n",
|
||||
" async for message in websocket:\n",
|
||||
" print(f\"Received: {message}\")\n",
|
||||
" await websocket.send(f\"Echo: {message}\")\n",
|
||||
" await websocket.send(json.dumps({\"message\": \"Hello from server!\"}))\n",
|
||||
" except websockets.exceptions.ConnectionClosed:\n",
|
||||
" print(\"Client disconnected\")\n",
|
||||
"\n",
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
import asyncio
|
||||
import websockets
|
||||
import json # 导入 json 模块
|
||||
|
||||
# WebSocket 服务器处理函数
|
||||
async def echo(websocket):
|
||||
async for message in websocket:
|
||||
print(f"收到客户端消息: {message}")
|
||||
# 发送响应给客户端
|
||||
response = {"respond": "Hello, Client!"}
|
||||
await websocket.send(json.dumps(response)) # 将字典转换为 JSON 字符串
|
||||
print(f"已发送响应: {response}")
|
||||
|
||||
# 启动服务器
|
||||
async def main():
|
||||
async with websockets.serve(echo, "localhost", 8765):
|
||||
await asyncio.Future() # 保持服务器运行
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("WebSocket 服务器已启动,监听 ws://localhost:8765")
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user