Vishaltiwari2019's picture
Update app.py
9a57be1 verified
raw
history blame
1.33 kB
import gradio as gr
import nltk
# Download the VADER lexicon
nltk.download('vader_lexicon')
# Rest of your code
from nltk.sentiment import 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
sia = SentimentIntensityAnalyzer()
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()