fix tts interface error (#2197)

### What problem does this PR solve?

fix tts interface error

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Zhedong Cen <cenzhedong2@126.com>
Co-authored-by: Kevin Hu <kevinhu.sh@gmail.com>
This commit is contained in:
黄腾
2024-09-02 18:40:57 +08:00
committed by GitHub
parent b9c383612d
commit ad09d4bb24
3 changed files with 23 additions and 9 deletions

View File

@ -21,7 +21,7 @@ import ormsgpack
from pydantic import BaseModel, conint
from rag.utils import num_tokens_from_string
import json
import re
class ServeReferenceAudio(BaseModel):
audio: bytes
@ -50,9 +50,11 @@ class Base(ABC):
def __init__(self, key, model_name, base_url):
pass
def transcription(self, audio):
def tts(self, audio):
pass
def normalize_text(text):
return re.sub(r'(\*\*|##\d+\$\$|#)', '', text)
class FishAudioTTS(Base):
def __init__(self, key, model_name, base_url="https://api.fish.audio/v1/tts"):
@ -66,10 +68,11 @@ class FishAudioTTS(Base):
self.ref_id = key.get("fish_audio_refid")
self.base_url = base_url
def transcription(self, text):
def tts(self, text):
from http import HTTPStatus
request = request = ServeTTSRequest(text=text, reference_id=self.ref_id)
text = self.normalize_text(text)
request = ServeTTSRequest(text=text, reference_id=self.ref_id)
with httpx.Client() as client:
try: