Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio.inputs import Textbox
|
| 3 |
|
| 4 |
-
import nltk
|
| 5 |
-
nltk.download('punkt')
|
| 6 |
-
from nltk.tokenize import sent_tokenize, word_tokenize
|
| 7 |
-
|
| 8 |
import re
|
| 9 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
| 10 |
from datasets import load_dataset
|
|
@@ -57,18 +53,8 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
| 57 |
|
| 58 |
# Remove line breaks
|
| 59 |
text = re.sub(r"\n", " ", text)
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
tokens = []
|
| 63 |
-
for sentence in sentences:
|
| 64 |
-
tokens.extend(word_tokenize(sentence))
|
| 65 |
-
|
| 66 |
-
if len(tokens) <= max_tokens:
|
| 67 |
-
return text
|
| 68 |
-
|
| 69 |
-
cut_tokens = tokens[:max_tokens]
|
| 70 |
-
cut = ' '.join(cut_tokens)
|
| 71 |
-
return cut
|
| 72 |
|
| 73 |
def save_audio_to_s3(audio):
|
| 74 |
# Create an instance of the S3 client
|
|
@@ -86,8 +72,9 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
| 86 |
# Preprocess text and recortar
|
| 87 |
text = cut_text(text, max_tokens=500)
|
| 88 |
|
| 89 |
-
# Divide el texto en segmentos de
|
| 90 |
-
|
|
|
|
| 91 |
|
| 92 |
# Generar audio para cada segmento y combinarlos
|
| 93 |
audio_segments = []
|
|
@@ -106,10 +93,11 @@ def generateAudio(text_to_audio, s3_save_as):
|
|
| 106 |
audio_buffer = BytesIO()
|
| 107 |
sf.write(audio_buffer, combined_audio.cpu().numpy(), samplerate=16000, format='WAV')
|
| 108 |
audio_buffer.seek(0)
|
| 109 |
-
|
| 110 |
# Guardar el audio combinado en S3
|
| 111 |
save_audio_to_s3(audio_buffer)
|
| 112 |
-
|
|
|
|
| 113 |
save_text_to_speech(text_to_audio, 2271)
|
| 114 |
return s3_save_as
|
| 115 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from gradio.inputs import Textbox
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
import re
|
| 5 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
| 6 |
from datasets import load_dataset
|
|
|
|
| 53 |
|
| 54 |
# Remove line breaks
|
| 55 |
text = re.sub(r"\n", " ", text)
|
| 56 |
+
|
| 57 |
+
return text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
def save_audio_to_s3(audio):
|
| 60 |
# Create an instance of the S3 client
|
|
|
|
| 72 |
# Preprocess text and recortar
|
| 73 |
text = cut_text(text, max_tokens=500)
|
| 74 |
|
| 75 |
+
# Divide el texto en segmentos de 30 palabras
|
| 76 |
+
palabras = text.split()
|
| 77 |
+
segmentos = [' '.join(palabras[i:i+30]) for i in range(0, len(palabras), 30)]
|
| 78 |
|
| 79 |
# Generar audio para cada segmento y combinarlos
|
| 80 |
audio_segments = []
|
|
|
|
| 93 |
audio_buffer = BytesIO()
|
| 94 |
sf.write(audio_buffer, combined_audio.cpu().numpy(), samplerate=16000, format='WAV')
|
| 95 |
audio_buffer.seek(0)
|
| 96 |
+
|
| 97 |
# Guardar el audio combinado en S3
|
| 98 |
save_audio_to_s3(audio_buffer)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
save_text_to_speech(text_to_audio, 2271)
|
| 102 |
return s3_save_as
|
| 103 |
|