diff --git a/app.py b/app.py index 30ce45d..660f0df 100644 --- a/app.py +++ b/app.py @@ -5,10 +5,9 @@ from fastapi.responses import StreamingResponse from io import BytesIO import uvicorn -from bs4 import BeautifulSoup -from markdown import markdown import re + app = FastAPI() @@ -349,22 +348,6 @@ class TTSRequest(BaseModel): voice: str - -def markdown_to_text(markdown_string): - """ Converts a markdown string to plaintext """ - - # md -> html -> text since BeautifulSoup can extract text cleanly - html = markdown(markdown_string) - - # remove code snippets - html = re.sub(r'
(.*?)
', ' ', html) - html = re.sub(r'(.*?)', ' ', html) - - # extract text - soup = BeautifulSoup(html, "html.parser") - text = ''.join(soup.findAll(string=True)) - - return text # Função para geração de fala a partir do texto async def text_to_speech(input_text, voice_short_name): communicate = edge_tts.Communicate(input_text, voice_short_name) @@ -376,6 +359,14 @@ async def text_to_speech(input_text, voice_short_name): return tmp_path +def clear(texto): + """ + Remove todos os caracteres "*" e "#" de um texto, + incluindo múltiplas ocorrências como "##", "**", "***", "####", etc. + """ + novo_texto = re.sub(r"[\*\#]+", "", texto) + return novo_texto + # Endpoint para converter texto em fala @app.post("/v1/audio/speech") async def generate_speech(request: TTSRequest): @@ -388,7 +379,7 @@ async def generate_speech(request: TTSRequest): selected_voice = voice_mapping["default"][request.voice] # Gerar o arquivo de áudio - audio_path = await text_to_speech(markdown_to_text(request.input), selected_voice) + audio_path = await text_to_speech(clear(request.input), selected_voice) # Retornar o arquivo de áudio como streaming with open(audio_path, "rb") as audio_file: diff --git a/src/plain-text-markdown-extention b/src/plain-text-markdown-extention new file mode 160000 index 0000000..8740e7e --- /dev/null +++ b/src/plain-text-markdown-extention @@ -0,0 +1 @@ +Subproject commit 8740e7ee364ac8ae9c436dcff58f8bb862ce93e5