Spaces:
Runtime error
Runtime error
File size: 1,281 Bytes
98bb2cc |
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 |
import streamlit as st
import speech_recognition as sr
from textblob import TextBlob
# Initialize Speech Recognition
recognizer = sr.Recognizer()
# Function to analyze sentiment and generate emoji
def analyze_sentiment(text):
blob = TextBlob(text)
sentiment_score = blob.sentiment.polarity
if sentiment_score > 0.5:
emoji = "π"
elif sentiment_score < -0.5:
emoji = "π"
else:
emoji = "π"
return emoji
# Streamlit app
st.title("Voice-to-Text Chatbot")
# Record voice input
with st.echo():
st.write("Click the button and speak...")
try:
with sr.Microphone() as source:
st.write("Recording...")
audio_data = recognizer.record(source, duration=5) # Adjust duration as needed
st.write("Processing...")
# Convert speech to text
text = recognizer.recognize_google(audio_data)
st.write(f"You said: {text}")
# Analyze sentiment and generate emoji
emoji = analyze_sentiment(text)
st.write(f"Sentiment: {emoji}")
except sr.RequestError as e:
st.error("Could not request results; {0}".format(e))
except sr.UnknownValueError:
st.error("Could not understand audio") |