|
import gradio as gr |
|
from gtts import gTTS |
|
|
|
|
|
def text_to_speech(sentence): |
|
tts = gTTS(sentence) |
|
tts.save("output.mp3") |
|
return sentence, "output.mp3" |
|
|
|
|
|
sentences = [ |
|
"In a small coastal town edged by jagged cliffs and vast, open sea, stood an old lighthouse that had guarded the mariners for generations.", |
|
"The lighthouse keeper, Mr. Elias, was an elderly man who had spent many years ensuring the light never failed, keeping ships safe from the dangerous rocks below.", |
|
"Elias's grandson, Jamie, loved to visit the lighthouse.", |
|
"He was fascinated by the stories his grandfather told of ships from distant lands and the many storms the lighthouse had withstood.", |
|
"However, over the years, fewer ships passed by, and the town council questioned the need to keep the lighthouse operational.", |
|
"They proposed using modern technology, which was cheaper and required less maintenance.", |
|
"One evening, as a fierce storm brewed, the council decided to test their new electronic navigation system, planning to retire the old lighthouse lamp after proving the new system's efficiency.", |
|
"Elias was heartbroken but knew he had to comply.", |
|
"That night, with the storm at its peak and the new system in place, the unthinkable happened—the electronic system failed due to the severe weather conditions." |
|
"In a panic, the town council realized their error. Without the lighthouse’s beam, ships at sea would be in grave danger.", |
|
"They rushed to Elias, asking for his help. Elias turned to Jamie, handing him a small, old lantern — a backup they had never thought they’d use.", |
|
"Hurry, take this to the top! It isn’t as bright, but it might just guide them in until we can fix the main light.", |
|
"Braving the howling wind and pelting rain, Jamie climbed the winding stairs of the lighthouse with the lantern.", |
|
"Reaching the top, he held the lantern high, its light flickering but steady. All he could do was hope it was enough.", |
|
"Miraculously, the small light was seen by a nearby ship. The captain, familiar with the lighthouse’s position, navigated away from the cliffs just in time, guiding the ship safely into the harbor.", |
|
"The town breathed a sigh of relief, and the council members were humbled by their near-disastrous decision.", |
|
"From that day on, the council reinstated the old lighthouse, restoring it and even enhancing its light to ensure higher visibility.", |
|
"Jamie learned the importance of resilience and tradition, and he took great pride in helping his grandfather.", |
|
"Inspired by the event, he started learning more about navigational technology, combining new methods with the reliable old ways.", |
|
"Years later, Jamie became the lighthouse keeper, just like his grandfather.", |
|
"He maintained the tradition of the lighthouse while integrating modern technology responsibly, ensuring that the lighthouse continued to be a beacon of safety and a symbol of the town’s enduring spirit.", |
|
"The story of the lighthouse keeper’s lantern became a cherished tale, reminding everyone that sometimes, the simplest solutions are the most effective in times of need.", |
|
"It taught the town the value of wisdom, experience, and the importance of blending the old with the new to navigate the future safely." |
|
] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=text_to_speech, |
|
inputs=gr.Dropdown(choices=sentences, label="Select a sentence"), |
|
outputs=[gr.Textbox(label="Selected Sentence"), gr.Audio(type="filepath")], |
|
title="Text-to-Speech App", |
|
description="Select a sentence and hear it read aloud using Google Text-to-Speech." |
|
) |
|
|
|
|
|
interface.launch() |