by MacV
ReadAloud: URL to Speech Converter
import logging
import os
from gunicorn.app.base import BaseApplication
from app_init import create_initialized_flask_app
from flask import request, jsonify, send_file
import requests
from bs4 import BeautifulSoup
from gtts import gTTS
import tempfile
# Flask app creation should be done by create_initialized_flask_app to avoid circular dependency problems.
app = create_initialized_flask_app()
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def scrape_article(url):
try:
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
# Remove script, style, nav, and footer elements
for element in soup(["script", "style", "nav", "footer", "header"]):
Created: | Last Updated:
Here's a step-by-step guide for using the ReadAloud: URL to Speech Converter template:
Introduction
The ReadAloud: URL to Speech Converter is a web application that allows users to convert news articles from URLs into speech using a text-to-speech API. This template provides a simple interface for users to input article URLs and receive audio versions of the content.
Getting Started
To begin using this template:
- Click the "Start with this Template" button in the Lazy Builder interface.
Test the Application
Once you've started with the template:
- Click the "Test" button in the Lazy Builder interface.
- Wait for the application to deploy. The Lazy CLI will provide you with a dedicated server link to access the web interface.
Using the Application
After deployment, follow these steps to use the ReadAloud converter:
- Open the provided server link in your web browser.
- You'll see a simple interface with a form to input a URL.
- Paste the URL of the news article you want to convert into the input field.
- Click the "Read Article" button.
- The application will scrape the article, convert it to speech, and provide an audio player.
- Use the audio player controls to listen to the converted article.
How It Works
The application performs the following steps:
- Scrapes the provided URL for article content.
- Converts the scraped text to speech using the gTTS (Google Text-to-Speech) library.
- Provides an audio player for the user to listen to the converted content.
Customization
You can customize the application by modifying the following files:
templates/home.html
: Adjust the HTML structure and layout of the main page.static/css/styles.css
: Modify the CSS to change the appearance of the application.static/js/home.js
: Update the JavaScript to alter the client-side functionality.
Conclusion
The ReadAloud: URL to Speech Converter template provides a straightforward way to convert web articles into audio format. It's ideal for users who prefer listening to content or need hands-free access to written articles.