Spaces:
Runtime error
Runtime error
import gradio as gr | |
from nltk.sentiment import SentimentIntensityAnalyzer | |
# Load sentiment analysis model | |
sia = SentimentIntensityAnalyzer() | |
# Text to Speech | |
title = "Text to Speech with Sentiment Analysis" | |
tts_examples = [ | |
"I love learning machine learning", | |
"How do you do?", | |
] | |
def get_sentiment(text): | |
# Get sentiment score | |
sentiment_score = sia.polarity_scores(text)["compound"] | |
# Adjust speech synthesis parameters based on sentiment | |
# You can customize this part based on the sentiment score. | |
# For example, if sentiment is positive, use a happy tone; if negative, use a sad tone. | |
# Modify the speech synthesis model and parameters accordingly. | |
# Use the sentiment_score to adjust the tone. | |
# Replace the following line with your desired text-to-speech model and parameters. | |
speech_output = f"This is a text with sentiment score {sentiment_score}: {text}" | |
return speech_output | |
tts_demo = gr.Interface( | |
fn=get_sentiment, | |
inputs="text", | |
outputs="audio", | |
examples=tts_examples, | |
title=title, | |
description="Give me something to say with sentiment analysis!", | |
) | |
demo = gr.TabbedInterface([tts_demo], ["Text to speech with sentiment"]) | |
if __name__ == "__main__": | |
demo.launch() | |