Spaces:
Runtime error
Runtime error
File size: 1,326 Bytes
785faa9 9a57be1 785faa9 9a57be1 ab11305 8b3ed52 7982942 9a57be1 7982942 ab11305 7982942 ab11305 8b3ed52 ab11305 7982942 ab11305 7982942 ab11305 7982942 ab11305 09094bd ab11305 09094bd ab11305 |
1 2 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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
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()
|