Get Fast AI Information with NewsVoiceAI

In at present’s fast-paced world, staying knowledgeable is essential, however discovering the time to learn prolonged information articles could be difficult. Moreover, consuming information in a single’s native language enhances understanding and engagement. Enter NewsVoiceAI, an modern software designed to revolutionize the way in which we entry information. By harnessing the facility of synthetic intelligence, NewsVoiceAI transforms stay English information articles into concise Punjabi audio summaries, making it simpler than ever to remain up to date whereas on the go.

On this complete article, we’ll delve into the workings of NewsVoiceAI, discover the cutting-edge applied sciences behind it, present a step-by-step information on how one can create the same software, and combine the precise code that brings this software to life.

Studying Outcomes

  • Learn the way NewsVoiceAI leverages AI to remodel stay information articles into concise, native-language audio summaries.
  • Perceive the applied sciences behind NewsVoiceAI, together with The Guardian API, OpenAI fashions, and text-to-speech conversion.
  • Achieve hands-on information of integrating APIs and utilizing Streamlit for constructing interactive purposes.
  • Uncover the right way to summarize and translate English information articles into Punjabi utilizing AI-driven fashions.
  • Discover the method of constructing a multilingual information summarizer with real-time information fetching and audio output.

This text was revealed as part of the Information Science Blogathon.

What’s NewsVoice?

Think about catching up on the newest information throughout your morning commute with out having to learn by way of prolonged articles or battle with language boundaries. NewsVoice was born out of the need to make information extra accessible, particularly for Punjabi-speaking audiences preferring consuming content material of their native language. The appliance bridges a number of gaps:

  • Time Constraints: Supplies concise summaries, saving customers time.
  • Language Accessibility: Interprets content material into Punjabi for native audio system.
  • Ease of Consumption: Converts textual content to speech, permitting for hands-free listening.

Whether or not you’re a busy skilled, a commuter, or somebody with visible impairments, NewsVoiceAI provides a seamless strategy to keep knowledgeable.

Key Options of NewsVoice

  • Stay Information Fetching: Pulls the newest information articles from respected sources like The Guardian utilizing their API.
  • AI-Powered Summarization: Makes use of superior AI fashions from OpenAI to condense prolonged articles into temporary summaries.
  • Punjabi Translation: Ensures regional accessibility by precisely translating summaries into Punjabi.
  • Textual content-to-Speech Conversion: Generates clear and natural-sounding Punjabi audio utilizing state-of-the-art TTS applied sciences.
  • Person-Pleasant Interface: Constructed with Streamlit, providing an interactive and intuitive person expertise.

How NewsVoice Works?

Let’s discover the step-by-step workflow of NewsVoice, integrating code snippets for instance every half.

Step1: Fetch Information Articles

Utilizing The Guardian API, NewsVoiceAI retrieves the highest stay information articles based mostly on predefined standards or person preferences.

Implementation

# Perform to fetch information articles from The Guardian API
def fetch_news(api_key):
    from theguardian import theguardian_content
    content material = theguardian_content.Content material(api=api_key)
    json_content = content material.get_content_response()
    strive:
        return content material.get_results(json_content)
    besides KeyError as e:
        st.error(f"Error fetching articles: {e}")
        return []

Clarification:

  • We use the theguardian library to work together with The Guardian API.
  • The fetch_news operate retrieves articles and handles any potential errors.

Step2: Fetch Article Content material

For every article, we fetch the total content material to arrange it for summarization.

Implementation

# Perform to fetch article content material
def fetch_article_content(article_url, api_key):
    response = requests.get(article_url, params={"api-key": api_key, "show-blocks": "all"})
    if response.status_code == 200:
        article_data = response.json()
        physique = article_data.get("response", {}).get("content material", {}).get("blocks", {}).get("physique", [])
        if physique:
            return " ".be a part of(block.get("bodyTextSummary", "") for block in physique)
    return None

Clarification:

  • The operate sends a GET request to the article’s API URL with parameters to retrieve the total content material.
  • It parses the JSON response to extract the textual content of the article.

Step3: Summarize and Translate Content material Utilizing OpenAI API

We use OpenAI’s GPT fashions to summarize the article after which translate the abstract into Punjabi.

Implementation

# Perform to summarize and translate content material utilizing OpenAI API
def summarize_and_translate(content material, api_key):
    import openai
    openai.api_key = api_key
    
    # Summarization Immediate
    summary_response = openai.ChatCompletion.create(
        mannequin="gpt-4", 
        messages=[
            {"role": "system", "content": "You are a helpful assistant that summarizes news articles concisely."},
            {"role": "user", "content": f"Summarize the following article content in 2-3 sentences:nn{content}"}
        ],
        max_tokens=100
    )
    abstract = summary_response.decisions[0].message.content material.strip()
    
    # Translation Immediate
    translation_response = openai.ChatCompletion.create(
        mannequin="gpt-3.5-turbo",
        messages=[
            {"role": "system", "content": "You are a professional translator specializing in English to Punjabi translations."},
            {"role": "user", "content": f"Translate the following text to Punjabi:nn{summary}"}
        ],
        max_tokens=150
    )
    translation = translation_response.decisions[0].message.content material.strip()
    
    return abstract, translation

Clarification:

  • We initialize the OpenAI API with the supplied key.
  • The summarize_and_translate operate first summarizes the article content material.
  • It then interprets the abstract into Punjabi.
  • Each operations use the ChatCompletion endpoint with applicable prompts.

Step4: Convert Punjabi Textual content to Speech Utilizing Sarvam TTS API

The translated textual content is transformed into audio utilizing the Sarvam TTS API.

Implementation

# Perform to transform Punjabi textual content to speech utilizing Sarvam TTS API
def punjabi_text_to_speech(punjabi_text, sarvam_api_key):
    url = "https://api.sarvam.ai/text-to-speech"
    
    # Cut up textual content into chunks of as much as 500 characters
    chunks = [punjabi_text[i:i+500] for i in vary(0, len(punjabi_text), 500)]
    audio_clips = []
    
    for i, chunk in enumerate(chunks):
        payload = {
            "inputs": [chunk],
            "target_language_code": "pa-IN",
            "speaker": "meera",
            "pitch": 0,
            "tempo": 1.0,
            "loudness": 1.2,
            "speech_sample_rate": 8000,
            "enable_preprocessing": True,
            "mannequin": "bulbul:v1"
        }
        headers = {
            "Content material-Kind": "software/json",
            "API-Subscription-Key": sarvam_api_key
        }
    
        response = requests.submit(url, headers=headers, json=payload)
    
        if response.status_code == 200:
            audio_base64 = response.json().get("audios")
            if audio_base64 and len(audio_base64) > 0:
                audio_clips.append(audio_base64[0])
            else:
                st.error(f"No audio present in response for chunk {i+1}.")
                return None
        else:
            st.error(f"Didn't convert chunk {i+1} to speech: {response.status_code} - {response.textual content}")
            return None
    
    # Mix all Base64 audio chunks right into a single string
    return "".be a part of(audio_clips)

Clarification:

  • The operate handles the API’s character restrict by splitting the textual content into chunks.
  • It sends every chunk to the TTS API and collects the Base64-encoded audio.
  • The audio chunks are concatenated to type the whole audio file.

Step5: Construct the Streamlit Interface

The person interface is constructed utilizing Streamlit, offering an interactive expertise.

Implementation

# Fundamental Streamlit App
def fundamental():
    st.set_page_config(
        page_title="NewsVoice: Multilingual Information Summaries",
        page_icon="📰",
        format="broad"
    )
    
    # Customized CSS for improved styling
    st.markdown("""
    <fashion>
    .main-title {
        font-size: 36px;
        coloration: #2C3E50;
        text-align: heart;
        margin-bottom: 30px;
    }
    .section-header {
        coloration: #3498DB;
        border-bottom: 2px stable #3498DB;
        padding-bottom: 10px;
    }
    </fashion>
    """, unsafe_allow_html=True)
    
    # App Title
    st.markdown('<h1 class="main-title">🌍 NewsVoice: Multilingual Information Summaries</h1>', unsafe_allow_html=True)
    
    # Sidebar for configuration
    st.sidebar.header("Information Configuration")
    num_articles = st.sidebar.slider("Variety of Articles", 1, 5, 3)
    
    # Fundamental Content material Space
    st.markdown('<h2 class="section-header">Newest Information Summaries</h2>', unsafe_allow_html=True)
    
    # Fetch and Course of Button
    if st.button("Fetch & Translate Information"):
        with st.spinner("Fetching and processing information..."):
            # Fetch information articles
            articles = fetch_news(GUARDIAN_API_KEY)
    
            if not articles:
                st.warning("No articles discovered. Please strive once more.")
            else:
                # Course of prime chosen variety of articles
                for article in articles[:num_articles]:
                    english_title = article.get('webTitle', 'No title obtainable')
                    article_url = article.get('apiUrl')
    
                    # Create a container for every article
                    with st.container():
                        st.subheader(english_title)
    
                        # Fetch article content material
                        article_content = fetch_article_content(article_url, GUARDIAN_API_KEY) if article_url else None
                        
                        if not article_content:
                            st.write("No content material obtainable for this text.")
                            proceed
    
                        strive:
                            # Summarize and Translate
                            abstract, punjabi_translation = summarize_and_translate(article_content, OPENAI_API_KEY)
                            
                            # Show English Abstract
                            st.markdown("**English Abstract:**")
                            st.write(abstract)
    
                            # Show Punjabi Translation
                            st.markdown("**Punjabi Translation:**")
                            st.write(punjabi_translation)
    
                            # Textual content-to-Speech
                            st.write("Producing Punjabi audio...")
                            audio_base64 = punjabi_text_to_speech(punjabi_translation, SARVAM_API_KEY)
    
                            if audio_base64:
                                audio_bytes = base64.b64decode(audio_base64)
                                st.audio(audio_bytes, format="audio/wav")
                            
                            # Add a divider between articles
                            st.markdown("---")
    
                        besides Exception as e:
                            st.error(f"Error processing article: {e}")
    
    # Footer
    st.markdown("""
    ---
    Powered by The Guardian API, OpenAI, and Sarvam TTS
    """)
    
# Run the Streamlit app
if __name__ == "__main__":
    fundamental()

Clarification:

  • The principle operate units up the Streamlit app, together with the web page configuration and styling.
  • The sidebar permits customers to pick the variety of articles.
  • The principle space shows the fetched information, summaries, translations, and audio.
  • Error dealing with ensures the app informs the person of any points throughout processing.
Step5: Build the Streamlit Interface: NewVoice AI

Try the Audio high quality within the recording uploaded within the README of this repository – NewsVoiceAI

The right way to Get hold of the APIs?

To efficiently construct and run NewsVoice, you’ll must get hold of API keys from the next companies:

  • The Guardian Open Platform API
  • OpenAI API
  • Sarvam TTS API

Under are step-by-step guides on the right way to purchase these API keys.

Guardian Open Platform API

The Guardian gives a free API that enables builders to entry content material from their huge repository of reports articles.

Steps to Get hold of The Guardian API Key:

  • Go to The Guardian Open Platform.
  • Scroll down and search for ‘Free instantaneous entry for builders’.
  • Click on on ‘Register for a developer key’.
  • Fill out the shape and Conform to the Phrases and Situations.
  • Submit Your Utility.
  • Retailer Your API Key Securely.

OpenAI API

OpenAI provides highly effective language fashions like GPT-4o and others, that are used for textual content summarization and translation in NewsVoiceAI.

Steps to Get hold of OpenAI API Key

  • Create an OpenAI Account.
  • Confirm Your E mail and Telephone Quantity.
  • Entry the API Dashboard
  • Generate a New API Key.
  • Retailer Your API Key Securely.

Vital Notes

Billing Data:

  • OpenAI’s APIs are paid companies. You’ll must arrange a cost technique below the
  • New customers might obtain free credit that expire after a sure interval.

Sarvam TTS API

Sarvam AI gives text-to-speech companies supporting a number of Indian languages, together with Punjabi with about ₹ 1,000 of free credit. Make good use of it!

Steps to Get hold of Sarvam TTS API Key:

  • Go to Sarvam AI‘s Web site.
  • Signal Up for an Account and Affirm Your E mail.
  • Entry the Developer Dashboard.
  • Generate an API Key.
  • Retailer Your API Key Securely.

Applied sciences Behind NewsVoice

Allow us to now talk about the applied sciences behind NewsVoice under:

The Guardian API

The Guardian API gives entry to a wealth of stay information articles and metadata. By integrating this API, NewsVoice ensures that customers obtain probably the most present and related information content material.

  • Customizable Queries: Fetch articles based mostly on sections, tags, or search phrases.
  • Wealthy Metadata: Entry article headlines, authors, publication dates, and extra.
  • Reliability: A trusted supply of reports with international protection.

OpenAI’s GPT Fashions

NewsVoiceAI leverages OpenAI’s highly effective multilingual language fashions to deal with each summarization and translation duties.

Summarization

  • Mannequin Used: Both gpt-4o’s November 2024 launch or gpt-4o-mini, relying on the specified steadiness between velocity and accuracy.
  • Performance: Converts prolonged information articles into concise summaries, capturing the essence of the content material.
  • Advantages: Reduces studying time whereas preserving key info.

Translation

  • Mannequin Used: The identical OpenAI fashions are employed for translation duties.
  • Performance: Interprets English summaries into Punjabi with excessive linguistic accuracy.
  • Advantages: Permits native Punjabi audio system to eat content material comfortably.

Textual content-to-Speech (TTS) Conversion

To transform translated textual content into speech, NewsVoiceAI makes use of superior TTS APIs that help Punjabi.

  • API Used: Sarvam TTS API or every other supplier that helps Punjabi.
  • Options:
    • Pure-Sounding Voice: Supplies a nice listening expertise.
    • Massive Textual content Dealing with: Able to processing prolonged texts by splitting them into manageable chunks.
  • Advantages: Makes information accessible to those that choose auditory studying or have visible impairments.

Streamlit

Streamlit is an open-source app framework used to create the interactive internet interface for NewsVoice.

  • Options:
    • Simple to Use: Simplifies the method of turning Python scripts into internet apps.
    • Interactive Widgets: Permits customers to work together with the app seamlessly.
    • Speedy Improvement: Permits fast prototyping and deployment.
  • Advantages: Supplies a user-friendly platform for customers to fetch, course of, and hearken to information effortlessly.

Conclusion

NewsVoiceAI represents a major step towards making information extra accessible and tailor-made to particular person wants. By integrating superior AI applied sciences from OpenAI and leveraging dependable information sources like The Guardian, the app transforms the way in which we eat information:

  • Accessibility: Breaks down language boundaries and caters to these with visible impairments.
  • Effectivity: Saves time by offering concise summaries.
  • Comfort: Permits for hands-free consumption by way of audio playback.

As know-how continues to evolve, purposes like NewsVoice will play a vital position in democratizing entry to info.

Strive it at present: NewsVoice GitHub Repository

Acknowledgments

  • The Guardian API: For offering stay information content material.
  • OpenAI: For the highly effective language fashions utilized in summarization and translation.
  • Sarvam TTS API: For enabling text-to-speech conversion in Punjabi.
  • Streamlit Neighborhood: For the open-source framework that powers the app’s interface.

Further Sources

Key Takeaways

  • NewsVoiceAI revolutionizes information consumption by offering concise Punjabi audio summaries of stay English information articles.
  • The appliance makes use of AI-powered summarization, translation, and text-to-speech applied sciences to make information accessible in real-time.
  • NewsVoiceAI helps time-saving, language accessibility, and hands-free listening for customers on the go.
  • The system integrates The Guardian API, OpenAI’s GPT fashions, Sarvam TTS, and Streamlit for a seamless person expertise.
  • NewsVoiceAI is right for busy professionals, commuters, and people with visible impairments who want quick access to present information.

Ceaselessly Requested Questions

Q1. What’s NewsVoiceAI and the way does it profit me?

A. NewsVoiceAI is an AI-powered software that transforms stay English information articles into concise Punjabi audio summaries. It advantages customers by saving time, breaking language boundaries, and offering an accessible, hands-free strategy to eat information.

Q2. Do I would like any technical experience to make use of NewsVoice?

A. No technical experience is required to make use of the applying as an end-user. You may merely work together with the user-friendly interface to fetch, learn, and hearken to information summaries. Nevertheless, in case you want to construct or customise the applying, fundamental information of Python and API integration can be useful.

Q3. Is NewsVoiceAI free to make use of?

A. The NewsVoiceAI software itself is open-source and free to make use of. Nevertheless, accessing sure APIs like OpenAI and Sarvam TTS might contain prices, particularly past their free utilization tiers. It’s vital to evaluate the pricing particulars of every API service you propose to make use of. Though, in case you plan on utilizing it domestically you might use open supply LLM’s utilizing Ollama.

This fall. How correct are the translations and summaries?

A. NewsVoiceAI makes use of superior AI fashions from OpenAI, identified for his or her excessive accuracy in language duties. Whereas the translations and summaries are usually dependable, they is probably not excellent as a result of nuances of language processing. Suggestions is welcome to assist enhance future variations.

Q5. Can I customise the variety of articles or choose particular information subjects?

A. Sure, the applying lets you choose the variety of articles to fetch by way of the sidebar slider. At the moment, matter choice isn’t obtainable, however future enhancements might embrace the power to filter information by classes or key phrases.

The media proven on this article is just not owned by Analytics Vidhya and is used on the Creator’s discretion.

Hello! I am Adarsh, a Enterprise Analytics graduate from ISB, presently deep into analysis and exploring new frontiers. I am tremendous enthusiastic about information science, AI, and all of the modern methods they’ll rework industries. Whether or not it is constructing fashions, engaged on information pipelines, or diving into machine studying, I like experimenting with the newest tech. AI is not simply my curiosity, it is the place I see the long run heading, and I am at all times excited to be part of that journey!