Spaces:
Sleeping
Sleeping
# app.py | |
# ============= | |
# This is a complete app.py file for a web scraping and text-to-speech app using gTTS and BeautifulSoup. | |
import requests | |
from bs4 import BeautifulSoup | |
from gtts import gTTS | |
import os | |
def get_text_from_webpage(url): | |
response = requests.get(url) | |
soup = BeautifulSoup(response.text, 'html.parser') | |
text = soup.get_text() | |
return text | |
def text_to_speech(text, lang='en'): | |
tts = gTTS(text=text, lang=lang) | |
tts.save("output.mp3") | |
os.system("start output.mp3") | |
def main(): | |
url = input("Enter the URL of the webpage: ") | |
text = get_text_from_webpage(url) | |
print("Extracted text from the webpage:") | |
print(text) | |
text_to_speech(text) | |
if __name__ == "__main__": | |
main() | |
# Dependencies | |
# ============= | |
# The following dependencies are required to run this app: | |
# - requests | |
# - beautifulsoup4 | |
# - gtts | |
# | |
# You can install these dependencies using pip: | |
# pip install requests beautifulsoup4 gtts | |