Spaces:
Sleeping
Sleeping
Update helper_fns.py
Browse files- helper_fns.py +52 -29
helper_fns.py
CHANGED
@@ -1,30 +1,53 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
return audio_path
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
from gtts import gTTS
|
4 |
+
from pydub import AudioSegment
|
5 |
+
|
6 |
+
|
7 |
+
#text to sppech function
|
8 |
+
def text_to_speech(text):
|
9 |
+
# Convert text to speech with a US accent using gTTS
|
10 |
+
tts = gTTS(text=text, lang='en', tld='us', slow=False)
|
11 |
+
tts.save('temp.mp3')
|
12 |
+
|
13 |
+
# Load the audio file
|
14 |
+
audio = AudioSegment.from_file('temp.mp3')
|
15 |
+
|
16 |
+
# Adjust the speed to approximately 170 wpm
|
17 |
+
playback_speed = 1.20
|
18 |
+
audio = audio.speedup(playback_speed=playback_speed)
|
19 |
+
|
20 |
+
# Save and return the adjusted audio file
|
21 |
+
final_filename = 'text_to_speech.mp3'
|
22 |
+
audio.export(final_filename, format='mp3')
|
23 |
+
|
24 |
+
return final_filename
|
25 |
+
|
26 |
+
|
27 |
+
def process_files():
|
28 |
+
return (gr.update(interactive=True,
|
29 |
+
elem_id='summary_button'),
|
30 |
+
gr.update(interactive = True, elem_id = 'summarization_method')
|
31 |
+
)
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
def get_summarization_method(option):
|
36 |
+
return option
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
def text_to_audio(text, model_name="facebook/fastspeech2-en-ljspeech"):
|
42 |
+
# Initialize the TTS pipeline
|
43 |
+
tts_pipeline = pipeline("text-to-speech", model=model_name)
|
44 |
+
|
45 |
+
# Generate the audio from text
|
46 |
+
audio = tts_pipeline(text)
|
47 |
+
|
48 |
+
# Save the audio to a file
|
49 |
+
audio_path = "output.wav"
|
50 |
+
with open(audio_path, "wb") as file:
|
51 |
+
file.write(audio["wav"])
|
52 |
+
|
53 |
return audio_path
|