MCPcopy
hub / github.com/mudler/LocalAI / TTS

Method TTS

backend/python/fish-speech/backend.py:311–420  ·  view source on GitHub ↗
(self, request, context)

Source from the content-addressed store, hash-verified

309 return self.audio_path
310
311 def TTS(self, request, context):
312 try:
313 from fish_speech.utils.schema import ServeTTSRequest, ServeReferenceAudio
314
315 if not request.dst:
316 return backend_pb2.Result(
317 success=False, message="dst (output path) is required"
318 )
319
320 text = request.text.strip()
321 if not text:
322 return backend_pb2.Result(success=False, message="Text is empty")
323
324 # Get generation parameters from options
325 top_p = self.options.get("top_p", 0.8)
326 temperature = self.options.get("temperature", 0.8)
327 repetition_penalty = self.options.get("repetition_penalty", 1.1)
328 max_new_tokens = self.options.get("max_new_tokens", 1024)
329 chunk_length = self.options.get("chunk_length", 200)
330
331 # Build references list for voice cloning
332 references = []
333 voice_name = request.voice if request.voice else None
334
335 if voice_name and voice_name in self.voices:
336 ref_audio_path = self._get_ref_audio_path(voice_name)
337 if ref_audio_path and os.path.exists(ref_audio_path):
338 with open(ref_audio_path, "rb") as f:
339 audio_bytes = f.read()
340 ref_text = self.voices[voice_name].get("ref_text", "")
341 references.append(
342 ServeReferenceAudio(audio=audio_bytes, text=ref_text)
343 )
344 print(
345 f"[INFO] Using voice '{voice_name}' with reference audio: {ref_audio_path}",
346 file=sys.stderr,
347 )
348 elif self.audio_path:
349 ref_audio_path = self._get_ref_audio_path()
350 if ref_audio_path and os.path.exists(ref_audio_path):
351 with open(ref_audio_path, "rb") as f:
352 audio_bytes = f.read()
353 ref_text = self.options.get("ref_text", "")
354 references.append(
355 ServeReferenceAudio(audio=audio_bytes, text=ref_text)
356 )
357 print(
358 f"[INFO] Using reference audio: {ref_audio_path}",
359 file=sys.stderr,
360 )
361
362 # Build ServeTTSRequest
363 tts_request = ServeTTSRequest(
364 text=text,
365 references=references,
366 top_p=top_p,
367 temperature=temperature,
368 repetition_penalty=repetition_penalty,

Callers

nothing calls this directly

Calls 7

_get_ref_audio_pathMethod · 0.95
openFunction · 0.85
appendMethod · 0.80
getMethod · 0.45
readMethod · 0.45
timeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected