mirror of
https://github.com/HiMeditator/auto-caption.git
synced 2026-02-04 04:14:42 +08:00
- 重构字幕引擎,将音频采集改为在新线程上进行 - 重构 audio2text 中的类,调整运行逻辑 - 更新 main 函数,添加对 Sosv 模型的支持 - 修改 AudioStream 类,默认使用 16000Hz 采样率
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
import socket
|
|
import threading
|
|
import json
|
|
from utils import shared_data, stdout_cmd, stderr
|
|
|
|
|
|
def handle_client(client_socket):
|
|
global shared_data
|
|
while shared_data.status == 'running':
|
|
try:
|
|
data = client_socket.recv(4096).decode('utf-8')
|
|
if not data:
|
|
break
|
|
data = json.loads(data)
|
|
|
|
if data['command'] == 'stop':
|
|
shared_data.status = 'stop'
|
|
break
|
|
except Exception as e:
|
|
stderr(f'Communication error: {e}')
|
|
break
|
|
|
|
shared_data.status = 'stop'
|
|
client_socket.close()
|
|
|
|
|
|
def start_server(port: int):
|
|
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
try:
|
|
server.bind(('localhost', port))
|
|
server.listen(1)
|
|
except Exception as e:
|
|
stderr(str(e))
|
|
stdout_cmd('kill')
|
|
return
|
|
stdout_cmd('connect')
|
|
|
|
client, addr = server.accept()
|
|
client_handler = threading.Thread(target=handle_client, args=(client,))
|
|
client_handler.daemon = True
|
|
client_handler.start()
|