Update app.py
Browse files
app.py
CHANGED
@@ -6,13 +6,10 @@ from transformers import AutoTokenizer
|
|
6 |
import soundfile as sf
|
7 |
from pydub import AudioSegment
|
8 |
import os
|
9 |
-
import
|
10 |
-
from nltk.data import find
|
11 |
from PyPDF2 import PdfReader
|
12 |
import textwrap
|
13 |
|
14 |
-
nltk.download('punkt')
|
15 |
-
|
16 |
# Device configuration
|
17 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
18 |
|
@@ -51,10 +48,11 @@ def pdf_to_text(pdf_path):
|
|
51 |
tts_model = ParlerTTSForConditionalGeneration.from_pretrained("parler-tts/parler-tts-large-v1").to(device)
|
52 |
tts_tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-large-v1")
|
53 |
|
54 |
-
# Function to split text into sentences
|
55 |
def split_text_into_sentences(text):
|
56 |
-
|
57 |
-
|
|
|
58 |
|
59 |
# Function to generate audio from text
|
60 |
def generate_wav_from_text(prompt, description, output_file_prefix):
|
|
|
6 |
import soundfile as sf
|
7 |
from pydub import AudioSegment
|
8 |
import os
|
9 |
+
import re
|
|
|
10 |
from PyPDF2 import PdfReader
|
11 |
import textwrap
|
12 |
|
|
|
|
|
13 |
# Device configuration
|
14 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
15 |
|
|
|
48 |
tts_model = ParlerTTSForConditionalGeneration.from_pretrained("parler-tts/parler-tts-large-v1").to(device)
|
49 |
tts_tokenizer = AutoTokenizer.from_pretrained("parler-tts/parler-tts-large-v1")
|
50 |
|
51 |
+
# Function to split text into sentences using regex
|
52 |
def split_text_into_sentences(text):
|
53 |
+
sentence_endings = re.compile(r'[.!?]')
|
54 |
+
sentences = sentence_endings.split(text)
|
55 |
+
return [sentence.strip() for sentence in sentences if sentence.strip()]
|
56 |
|
57 |
# Function to generate audio from text
|
58 |
def generate_wav_from_text(prompt, description, output_file_prefix):
|