Python Forum
Bot that can read info on the screen aloud...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bot that can read info on the screen aloud...
#1
Question:

I am developing a Python voice assistant for visually impaired users to help them search the web and gain information using voice commands. The assistant can currently perform searches, but I am struggling with making it read the content of web pages aloud.

Problem:

I need guidance on how to:

Open websites and extract text content from the web pages.

Read the extracted text content aloud using the existing pyttsx3 setup.

I haven't implemented any solution for this part yet, as I am unsure about the best approach or what additional libraries or tools are required.

What I've Tried:

I have researched libraries like BeautifulSoup for web scraping and libraries like requests to open web pages, but I am unsure how to integrate these with my current voice assistant setup.

What I'm Seeking:

Recommendations on how to open websites and extract text content using Python libraries.

Integration of the extracted content with pyttsx3 to read it aloud.

Code snippets or examples that could help with this implementation.

Additional Details:

Current Setup: I have a basic Python script using pyttsx3 for text-to-speech conversion.

Research: I have looked into BeautifulSoup for web scraping and requests for opening web pages but haven't figured out how to effectively use them in this context.

Issues: I am not sure how to proceed with opening web pages, extracting relevant text, and then having my voice assistant read it aloud.

Expectations vs. Reality:

Expected: The assistant should read out relevant text content from a web page.

Actual: I am currently unable to open web pages and extract the text content to read aloud.


code
import speech_recognition as sr
import pyttsx3
import datetime
import webbrowser
import time

print('Loading Sonic Surfing...')

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)

def speak(text):
engine.say(text)
engine.runAndWait()

def wishMe():
hour = datetime.datetime.now().hour
if 0 <= hour < 12:
speak("Good Morning!")
elif 12 <= hour < 18:
speak("Good Afternoon!")
else:
speak("Good Evening!")

def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
audio = r.listen(source)

try:
statement = r.recognize_google(audio, language='en-in')
print(f"user said: {statement}\n")
except Exception as e:
speak("I didn't hear you, please say that again")
return "none"
return statement.lower()

speak("Loading Sonic Surfing")
wishMe()

def get_weather():
# Simulated weather conditions based on time of day
hour = datetime.datetime.now().hour
if 6 <= hour < 12:
weather_desc = "sunny"
elif 12 <= hour < 18:
weather_desc = "cloudy"
else:
weather_desc = "clear"
return weather_desc

if __name__ == '__main__':
while True:
speak("What can I do for you?")
statement = takeCommand()
if statement == "none":
continue

if "exit" in statement or "goodbye" in statement or "turn off" in statement:
speak('Turning off Sonic Surfing.')
break

elif 'open youtube' in statement:
webbrowser.open_new_tab("https://youtube.com")
speak("YouTube is now open")
time.sleep(3)

elif 'search orange juice gaming' in statement:
webbrowser.open_new_tab("https://www.youtube.com/results?search_query=Orange+Juice+Gaming")
speak("Searching for Orange Juice Gaming on YouTube")
time.sleep(3)

elif 'open google' in statement:
webbrowser.open_new_tab("https://www.google.com")
speak("Google Chrome is open now")
time.sleep(5)

elif 'open gmail' in statement:
webbrowser.open_new_tab("https://mail.google.com")
speak("Google Mail is open now")
time.sleep(5)

elif 'what is the time' in statement or 'tell me the time' in statement or 'current time' in statement:
current_time = datetime.datetime.now().strftime("%H:%M")
speak(f"The time is {current_time}")

elif 'search' in statement:
search_query = statement.replace("search", "").strip()
if search_query:
webbrowser.open_new_tab(f"https://www.google.com/search?q={search_query}")
speak(f"Searching for {search_query} on Google")
time.sleep(5)

# Code for Google search
elif 'search' in statement and 'google' in statement:
search_query = statement.replace("search", "").replace("google", "").strip()
if search_query:
webbrowser.open_new_tab(f"https://www.google.com/search?q={search_query}")
speak(f"Searching for {search_query} on Google")
time.sleep(5)

elif 'what is the weather' in statement or 'weather' in statement:
weather_desc = get_weather()
speak(f"The weather is {weather_desc}.")

# Open Wikipedia website
elif 'open wikipedia' in statement:
webbrowser.open_new_tab("https://en.wikipedia.org")
speak("Wikipedia is now open")
Reply
#2
What have you tried? You will need to put forth an effort for someone to help.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(Jun-18-2024, 05:16 PM)menator01 Wrote: What have you tried? You will need to put forth an effort for someone to help.

i have made it more specific please check and see if its fine..
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is it possible for a Bot to read out the information on the screen aloud? RaySuS777 1 234 Jun-19-2024, 07:33 PM
Last Post: rodiongork
  I dont understand on how to create a Bot that can read info on the screen aloud RaySuS777 0 166 Jun-19-2024, 10:02 AM
Last Post: RaySuS777
  What is all the info in the info window in Idle? Pedroski55 3 850 Jul-08-2023, 11:26 AM
Last Post: DeaD_EyE
  wn = turtle.screen() AttributeError: module 'turtle' has no attribute 'screen' Shadower 1 6,318 Feb-06-2019, 01:25 AM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020