-12.3 C
United States of America
Monday, January 20, 2025

Get Fast AI Information with NewsVoiceAI


In right now’s fast-paced world, staying knowledgeable is essential, however discovering the time to learn prolonged information articles will be difficult. Moreover, consuming information in a single’s native language enhances understanding and engagement. Enter NewsVoiceAI, an modern software designed to revolutionize the best way we entry information. By harnessing the ability of synthetic intelligence, NewsVoiceAI transforms dwell 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 an identical software, and combine the precise code that brings this software to life.

Studying Outcomes

  • Find out how NewsVoiceAI leverages AI to remodel dwell 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.
  • Acquire hands-on information of integrating APIs and utilizing Streamlit for constructing interactive functions.
  • 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 printed as part of the Knowledge Science Blogathon.

What’s NewsVoice?

Think about catching up on the most recent information throughout your morning commute with out having to learn by way of prolonged articles or wrestle with language limitations. 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 applying bridges a number of gaps:

  • Time Constraints: Gives 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 gives a seamless method to keep knowledgeable.

Key Options of NewsVoice

  • Stay Information Fetching: Pulls the most recent 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 consumer expertise.

How NewsVoice Works?

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

Step1: Fetch Information Articles

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

Implementation

# Operate 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 perform retrieves articles and handles any potential errors.

Step2: Fetch Article Content material

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

Implementation

# Operate 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 part of(block.get("bodyTextSummary", "") for block in physique)
    return None

Clarification:

  • The perform 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

# Operate 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 offered key.
  • The summarize_and_translate perform first summarizes the article content material.
  • It then interprets the abstract into Punjabi.
  • Each operations use the ChatCompletion endpoint with acceptable 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

# Operate 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.publish(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 part of(audio_clips)

Clarification:

  • The perform 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 kind the entire audio file.

Step5: Construct the Streamlit Interface

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

Implementation

# Important Streamlit App
def predominant():
    st.set_page_config(
        page_title="NewsVoice: Multilingual Information Summaries",
        page_icon="📰",
        format="broad"
    )
    
    # Customized CSS for improved styling
    st.markdown("""
    <type>
    .main-title {
        font-size: 36px;
        coloration: #2C3E50;
        text-align: heart;
        margin-bottom: 30px;
    }
    .section-header {
        coloration: #3498DB;
        border-bottom: 2px strong #3498DB;
        padding-bottom: 10px;
    }
    </type>
    """, 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)
    
    # Important 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__":
    predominant()

Clarification:

  • The principle perform 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 consumer 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

Easy methods to Acquire the APIs?

To efficiently construct and run NewsVoice, you’ll must receive API keys from the next providers:

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

Beneath 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 permits builders to entry content material from their huge repository of stories articles.

Steps to Acquire The Guardian API Key:

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

OpenAI API

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

Steps to Acquire OpenAI API Key

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

Necessary Notes

Billing Info:

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

Sarvam TTS API

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

Steps to Acquire Sarvam TTS API Key:

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

Applied sciences Behind NewsVoice

Allow us to now focus on the applied sciences behind NewsVoice under:

The Guardian API

The Guardian API gives entry to a wealth of dwell information articles and metadata. By integrating this API, NewsVoice ensures that customers obtain essentially 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 stories with world 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 stability 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: Allows 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 assist Punjabi.

  • API Used: Sarvam TTS API or some other supplier that helps Punjabi.
  • Options:
    • Pure-Sounding Voice: Gives 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 favor 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.
    • Fast Growth: Allows fast prototyping and deployment.
  • Advantages: Gives a user-friendly platform for customers to fetch, course of, and take heed 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 best way we eat information:

  • Accessibility: Breaks down language limitations 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 expertise continues to evolve, functions like NewsVoice will play a vital position in democratizing entry to info.

Strive it right now: NewsVoice GitHub Repository

Acknowledgments

  • The Guardian API: For offering dwell 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.

Extra Sources

Key Takeaways

  • NewsVoiceAI revolutionizes information consumption by offering concise Punjabi audio summaries of dwell English information articles.
  • The applying 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 consumer expertise.
  • NewsVoiceAI is right for busy professionals, commuters, and people with visible impairments who want easy accessibility to present information.

Incessantly Requested Questions

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

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

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

A. No technical experience is required to make use of the appliance as an end-user. You may merely work together with the user-friendly interface to fetch, learn, and take heed to information summaries. Nevertheless, should you want to construct or customise the appliance, 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 assessment the pricing particulars of every API service you intend to make use of. Though, should you plan on utilizing it regionally it’s possible you’ll use open supply LLM’s utilizing Ollama.

This autumn. 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 good because of the nuances of language processing. Suggestions is welcome to assist enhance future variations.

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

A. Sure, the appliance lets you choose the variety of articles to fetch by way of the sidebar slider. At the moment, subject 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 isn’t owned by Analytics Vidhya and is used on the Creator’s discretion.

Hello! I am Adarsh, a Enterprise Analytics graduate from ISB, at the moment deep into analysis and exploring new frontiers. I am tremendous captivated with knowledge science, AI, and all of the modern methods they will remodel industries. Whether or not it is constructing fashions, engaged on knowledge pipelines, or diving into machine studying, I really like experimenting with the most recent tech. AI is not simply my curiosity, it is the place I see the longer term heading, and I am all the time excited to be part of that journey!

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles