Text-to-Speech
Transformers
ONNX
GGUF
Chinese
English
voice-dialogue
speech-recognition
large-language-model
asr
tts
llm
chinese
english
real-time
conversational
Instructions to use MoYoYoTech/VoiceDialogue with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MoYoYoTech/VoiceDialogue with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-to-speech", model="MoYoYoTech/VoiceDialogue") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("MoYoYoTech/VoiceDialogue", dtype="auto") - llama-cpp-python
How to use MoYoYoTech/VoiceDialogue with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="MoYoYoTech/VoiceDialogue", filename="assets/models/llm/qwen/Qwen3-8B-Q6_K.gguf", )
llm.create_chat_completion( messages = "\"The answer to the universe is 42\"" )
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use MoYoYoTech/VoiceDialogue with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K # Run inference directly in the terminal: llama-cli -hf MoYoYoTech/VoiceDialogue:Q6_K
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K # Run inference directly in the terminal: llama-cli -hf MoYoYoTech/VoiceDialogue:Q6_K
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K # Run inference directly in the terminal: ./llama-cli -hf MoYoYoTech/VoiceDialogue:Q6_K
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K # Run inference directly in the terminal: ./build/bin/llama-cli -hf MoYoYoTech/VoiceDialogue:Q6_K
Use Docker
docker model run hf.co/MoYoYoTech/VoiceDialogue:Q6_K
- LM Studio
- Jan
- Ollama
How to use MoYoYoTech/VoiceDialogue with Ollama:
ollama run hf.co/MoYoYoTech/VoiceDialogue:Q6_K
- Unsloth Studio new
How to use MoYoYoTech/VoiceDialogue with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MoYoYoTech/VoiceDialogue to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MoYoYoTech/VoiceDialogue to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for MoYoYoTech/VoiceDialogue to start chatting
- Pi new
How to use MoYoYoTech/VoiceDialogue with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "MoYoYoTech/VoiceDialogue:Q6_K" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use MoYoYoTech/VoiceDialogue with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf MoYoYoTech/VoiceDialogue:Q6_K
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default MoYoYoTech/VoiceDialogue:Q6_K
Run Hermes
hermes
- Docker Model Runner
How to use MoYoYoTech/VoiceDialogue with Docker Model Runner:
docker model run hf.co/MoYoYoTech/VoiceDialogue:Q6_K
- Lemonade
How to use MoYoYoTech/VoiceDialogue with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull MoYoYoTech/VoiceDialogue:Q6_K
Run and chat with the model
lemonade run user.VoiceDialogue-Q6_K
List all available models
lemonade list
liumaolin commited on
Commit ·
b115e26
1
Parent(s): 29766c6
Enhance WebSocket handling for connection management and reliability
Browse files- Add message broadcasting support to `WebSocketConnectionManager`.
- Improve connection cleanup for disconnected clients.
- Refine WebSocket endpoint to handle client disconnects and queue tasks more gracefully.
src/voice_dialogue/api/routes/websocket_routes.py
CHANGED
|
@@ -1,10 +1,8 @@
|
|
| 1 |
import asyncio
|
| 2 |
from contextlib import asynccontextmanager
|
| 3 |
-
from queue import Empty
|
| 4 |
from typing import Set, Dict
|
| 5 |
|
| 6 |
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
| 7 |
-
from fastapi.websockets import WebSocketState
|
| 8 |
|
| 9 |
from voice_dialogue.core.constants import websocket_message_queue, session_manager
|
| 10 |
from voice_dialogue.utils.logger import logger
|
|
@@ -82,6 +80,26 @@ class WebSocketConnectionManager:
|
|
| 82 |
for connection in disconnected_connections:
|
| 83 |
await self.disconnect(connection)
|
| 84 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
@property
|
| 86 |
def connection_count(self) -> int:
|
| 87 |
"""获取当前连接数"""
|
|
@@ -118,18 +136,43 @@ async def websocket_connection_context(websocket: WebSocket):
|
|
| 118 |
@ws.websocket("/api/v1/ws")
|
| 119 |
async def websocket_endpoint(websocket: WebSocket):
|
| 120 |
"""WebSocket连接端点"""
|
| 121 |
-
async with websocket_connection_context(websocket):
|
|
|
|
|
|
|
|
|
|
| 122 |
try:
|
| 123 |
# 保持连接活跃
|
| 124 |
-
while
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
except WebSocketDisconnect:
|
| 133 |
-
logger.info("WebSocket连接断开")
|
| 134 |
except Exception as e:
|
| 135 |
logger.error(f"WebSocket连接异常: {e}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import asyncio
|
| 2 |
from contextlib import asynccontextmanager
|
|
|
|
| 3 |
from typing import Set, Dict
|
| 4 |
|
| 5 |
from fastapi import APIRouter, WebSocket, WebSocketDisconnect
|
|
|
|
| 6 |
|
| 7 |
from voice_dialogue.core.constants import websocket_message_queue, session_manager
|
| 8 |
from voice_dialogue.utils.logger import logger
|
|
|
|
| 80 |
for connection in disconnected_connections:
|
| 81 |
await self.disconnect(connection)
|
| 82 |
|
| 83 |
+
async def broadcast(self, message: dict):
|
| 84 |
+
"""向所有活跃连接广播消息"""
|
| 85 |
+
async with self._lock:
|
| 86 |
+
if not self._connections:
|
| 87 |
+
return
|
| 88 |
+
|
| 89 |
+
connections = list(self._connections)
|
| 90 |
+
disconnected_connections = []
|
| 91 |
+
|
| 92 |
+
for connection in connections:
|
| 93 |
+
try:
|
| 94 |
+
await connection.send_json(message)
|
| 95 |
+
except Exception as e:
|
| 96 |
+
logger.warning(f"广播消息失败,标记连接为断开: {e}")
|
| 97 |
+
disconnected_connections.append(connection)
|
| 98 |
+
|
| 99 |
+
# 清理断开的连接
|
| 100 |
+
for connection in disconnected_connections:
|
| 101 |
+
await self.disconnect(connection)
|
| 102 |
+
|
| 103 |
@property
|
| 104 |
def connection_count(self) -> int:
|
| 105 |
"""获取当前连接数"""
|
|
|
|
| 136 |
@ws.websocket("/api/v1/ws")
|
| 137 |
async def websocket_endpoint(websocket: WebSocket):
|
| 138 |
"""WebSocket连接端点"""
|
| 139 |
+
async with websocket_connection_context(websocket) as websocket_connection:
|
| 140 |
+
disconnect_task = asyncio.create_task(websocket_connection.receive_text())
|
| 141 |
+
get_message_task = None
|
| 142 |
+
|
| 143 |
try:
|
| 144 |
# 保持连接活跃
|
| 145 |
+
while True:
|
| 146 |
+
get_message_task = asyncio.create_task(websocket_message_queue.get())
|
| 147 |
+
|
| 148 |
+
done, pending = await asyncio.wait(
|
| 149 |
+
{disconnect_task, get_message_task},
|
| 150 |
+
return_when=asyncio.FIRST_COMPLETED
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
# 如果是 disconnect_task 完成,说明客户端已断开连接。
|
| 154 |
+
if disconnect_task in done:
|
| 155 |
+
# 这将重新引发 WebSocketDisconnect 异常并跳出循环。
|
| 156 |
+
if get_message_task in done:
|
| 157 |
+
# 如果有,将消息放回队列,然后让连接断开
|
| 158 |
+
message = get_message_task.result()
|
| 159 |
+
websocket_message_queue.put_nowait(message)
|
| 160 |
+
logger.info("连接已关闭,将消息重新入队。")
|
| 161 |
+
|
| 162 |
+
disconnect_task.result()
|
| 163 |
+
|
| 164 |
+
# 如果是 queue_task 完成,说明有可用的消息。
|
| 165 |
+
if get_message_task in done:
|
| 166 |
+
message = get_message_task.result()
|
| 167 |
+
await connection_manager.send_to_session(message.session_id, message.model_dump())
|
| 168 |
+
# queue_task 现已完成,我们将在循环的下一次迭代中创建一个新的。
|
| 169 |
|
| 170 |
except WebSocketDisconnect:
|
| 171 |
+
logger.info("WebSocket连接已断开")
|
| 172 |
except Exception as e:
|
| 173 |
logger.error(f"WebSocket连接异常: {e}")
|
| 174 |
+
finally:
|
| 175 |
+
# 确保如果循环因其他原因退出,disconnect_task 会被取消。
|
| 176 |
+
disconnect_task.cancel()
|
| 177 |
+
if get_message_task and not get_message_task.done():
|
| 178 |
+
get_message_task.cancel()
|