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 ·
1ae18a4
1
Parent(s): 8d91cc1
Refactor sentence processing in `text_generator.py`: centralize sentence end mark sets, streamline `_should_end_sentence` logic, and eliminate redundant parameter passing for improved clarity and maintainability.
Browse files
src/VoiceDialogue/services/text/text_generator.py
CHANGED
|
@@ -35,6 +35,10 @@ class LLMResponseGenerator(BaseThread):
|
|
| 35 |
self.user_question_queue = user_question_queue
|
| 36 |
self.generated_answer_queue = generated_answer_queue
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
def _get_prompt_by_language(self, language: str) -> str:
|
| 39 |
"""根据语言获取对应的 prompt"""
|
| 40 |
if language == "zh":
|
|
@@ -64,19 +68,24 @@ class LLMResponseGenerator(BaseThread):
|
|
| 64 |
messages = memory.load_memory_variables({})[key]
|
| 65 |
return InMemoryChatMessageHistory(messages=messages)
|
| 66 |
|
| 67 |
-
def _should_end_sentence(self, sentence: str, sentence_end_mark: str,
|
| 68 |
-
sentence_end_marks: set, is_first_sentence: bool) -> bool:
|
| 69 |
"""判断是否应该结束当前句子"""
|
| 70 |
-
if not sentence or sentence_end_mark not in sentence_end_marks:
|
| 71 |
return False
|
| 72 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# 第一个句子的特殊处理逻辑
|
| 74 |
if is_first_sentence:
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# 普通句子的判断逻辑
|
| 79 |
-
if
|
| 80 |
sentence_words = len(sentence)
|
| 81 |
else:
|
| 82 |
sentence_words = len(sentence.split())
|
|
@@ -105,9 +114,6 @@ class LLMResponseGenerator(BaseThread):
|
|
| 105 |
|
| 106 |
def _process_voice_task(self, voice_task: VoiceTask) -> None:
|
| 107 |
"""处理单个语音任务"""
|
| 108 |
-
english_sentence_end_marks = {'!', '?', '.', ',', ':', ';'}
|
| 109 |
-
chinese_sentence_end_marks = {',', '。', '!', '?', ':', ';', '、'}
|
| 110 |
-
sentence_end_marks = english_sentence_end_marks | chinese_sentence_end_marks
|
| 111 |
|
| 112 |
chunks = []
|
| 113 |
answer_index = 0
|
|
@@ -124,9 +130,9 @@ class LLMResponseGenerator(BaseThread):
|
|
| 124 |
|
| 125 |
try:
|
| 126 |
for chunk in pipeline.stream(input={'input': user_question}, config=config):
|
| 127 |
-
|
| 128 |
-
if not chunk_content:
|
| 129 |
continue
|
|
|
|
| 130 |
|
| 131 |
sentence_end_mark, remain_content = self._process_chunk_content(chunk_content)
|
| 132 |
chunks.append(sentence_end_mark)
|
|
@@ -136,7 +142,7 @@ class LLMResponseGenerator(BaseThread):
|
|
| 136 |
continue
|
| 137 |
|
| 138 |
# 检查是否应该结束当前句子
|
| 139 |
-
if self._should_end_sentence(sentence, sentence_end_mark,
|
| 140 |
self._send_sentence_to_queue(voice_task, sentence, answer_index)
|
| 141 |
chunks = self._reset_chunks(remain_content)
|
| 142 |
answer_index += 1
|
|
@@ -146,19 +152,18 @@ class LLMResponseGenerator(BaseThread):
|
|
| 146 |
chunks.append(remain_content)
|
| 147 |
|
| 148 |
# 处理最后剩余的 chunks
|
| 149 |
-
self._handle_remaining_chunks(voice_task, chunks, answer_index
|
| 150 |
|
| 151 |
except Exception as e:
|
| 152 |
print(f'处理语音任务时发生错误: {e}')
|
| 153 |
|
| 154 |
-
def _handle_remaining_chunks(self, voice_task: VoiceTask, chunks: list,
|
| 155 |
-
answer_index: int, sentence_end_marks: set) -> None:
|
| 156 |
"""处理剩余的 chunks"""
|
| 157 |
if not chunks:
|
| 158 |
return
|
| 159 |
|
| 160 |
sentence = preprocess_sentence_text(chunks)
|
| 161 |
-
if not sentence or sentence.strip() in sentence_end_marks:
|
| 162 |
return
|
| 163 |
|
| 164 |
self._send_sentence_to_queue(voice_task, sentence, answer_index)
|
|
|
|
| 35 |
self.user_question_queue = user_question_queue
|
| 36 |
self.generated_answer_queue = generated_answer_queue
|
| 37 |
|
| 38 |
+
self.english_sentence_end_marks = {'!', '?', '.', ',', ':', ';'}
|
| 39 |
+
self.chinese_sentence_end_marks = {',', '。', '!', '?', ':', ';', '、'}
|
| 40 |
+
self.sentence_end_marks = self.english_sentence_end_marks | self.chinese_sentence_end_marks
|
| 41 |
+
|
| 42 |
def _get_prompt_by_language(self, language: str) -> str:
|
| 43 |
"""根据语言获取对应的 prompt"""
|
| 44 |
if language == "zh":
|
|
|
|
| 68 |
messages = memory.load_memory_variables({})[key]
|
| 69 |
return InMemoryChatMessageHistory(messages=messages)
|
| 70 |
|
| 71 |
+
def _should_end_sentence(self, sentence: str, sentence_end_mark: str, is_first_sentence: bool) -> bool:
|
|
|
|
| 72 |
"""判断是否应该结束当前句子"""
|
| 73 |
+
if not sentence or sentence_end_mark not in self.sentence_end_marks:
|
| 74 |
return False
|
| 75 |
|
| 76 |
+
is_chinese_sentence = False
|
| 77 |
+
if sentence_end_mark in self.chinese_sentence_end_marks:
|
| 78 |
+
is_chinese_sentence = True
|
| 79 |
+
|
| 80 |
# 第一个句子的特殊处理逻辑
|
| 81 |
if is_first_sentence:
|
| 82 |
+
if is_chinese_sentence:
|
| 83 |
+
return (len(sentence) > 2 and sentence_end_mark in self.chinese_sentence_end_marks)
|
| 84 |
+
else:
|
| 85 |
+
return (len(sentence.split()) > 1 and sentence_end_mark in self.english_sentence_end_marks)
|
| 86 |
|
| 87 |
# 普通句子的判断逻辑
|
| 88 |
+
if is_chinese_sentence:
|
| 89 |
sentence_words = len(sentence)
|
| 90 |
else:
|
| 91 |
sentence_words = len(sentence.split())
|
|
|
|
| 114 |
|
| 115 |
def _process_voice_task(self, voice_task: VoiceTask) -> None:
|
| 116 |
"""处理单个语音任务"""
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
chunks = []
|
| 119 |
answer_index = 0
|
|
|
|
| 130 |
|
| 131 |
try:
|
| 132 |
for chunk in pipeline.stream(input={'input': user_question}, config=config):
|
| 133 |
+
if not chunk.content.strip():
|
|
|
|
| 134 |
continue
|
| 135 |
+
chunk_content = f'{chunk.content}'
|
| 136 |
|
| 137 |
sentence_end_mark, remain_content = self._process_chunk_content(chunk_content)
|
| 138 |
chunks.append(sentence_end_mark)
|
|
|
|
| 142 |
continue
|
| 143 |
|
| 144 |
# 检查是否应该结束当前句子
|
| 145 |
+
if self._should_end_sentence(sentence, sentence_end_mark, is_first_sentence):
|
| 146 |
self._send_sentence_to_queue(voice_task, sentence, answer_index)
|
| 147 |
chunks = self._reset_chunks(remain_content)
|
| 148 |
answer_index += 1
|
|
|
|
| 152 |
chunks.append(remain_content)
|
| 153 |
|
| 154 |
# 处理最后剩余的 chunks
|
| 155 |
+
self._handle_remaining_chunks(voice_task, chunks, answer_index)
|
| 156 |
|
| 157 |
except Exception as e:
|
| 158 |
print(f'处理语音任务时发生错误: {e}')
|
| 159 |
|
| 160 |
+
def _handle_remaining_chunks(self, voice_task: VoiceTask, chunks: list, answer_index: int) -> None:
|
|
|
|
| 161 |
"""处理剩余的 chunks"""
|
| 162 |
if not chunks:
|
| 163 |
return
|
| 164 |
|
| 165 |
sentence = preprocess_sentence_text(chunks)
|
| 166 |
+
if not sentence or sentence.strip() in self.sentence_end_marks:
|
| 167 |
return
|
| 168 |
|
| 169 |
self._send_sentence_to_queue(voice_task, sentence, answer_index)
|