How to make voice-enabled Wikipedia in Python?

How to make voice-enabled Wikipedia in Python?

The python community provides a lot of open-source, user made libraries to use along with some libraries from companies like Google.

This project will enable you to search anything on Wikipedia using your voice.

Here we will use the following libraries 

  • SpeechRecognition - To recognize our speech and convert it to text.
  • Wikipedia - This library provides access to Wikipedia content by scrapping the contents for you.
  • gTTs - The Google-Text-To-Speech library provided by Google uses its huge database and algorithms to convert your text to speech.
  • playsound - This library help to play audio files.

Source Code  

import speech_recognition as sr
import wikipedia
from gtts import gTTS
from playsound import playsound

speech=sr.Recognizer()

with sr.Microphone() as source:
    print("Say something")

    playsound("audio/ss.mp3")
    audio=speech.listen(source)


try:
    search=speech.recognize_google(audio)
    search_query=gTTS(search,lang="en")			
    search_query.save("audio/search.mp3")

    print("Searching for " + search)
    playsound("audio/sf.mp3")
    playsound("audio/search.mp3")


    summary=wikipedia.summary(search,sentences=1)
    print(summary)
    

    tts=gTTS(summary,lang="en")
    tts.save("audio/wiki.mp3")
    playsound("audio/wiki.mp3")

except:
    print("Run program again")
    playsound("audio/error.mp3")

The audio files used in the program and the complete package is provided at the following link - Wikipedia-Using-Voice


Comments / Answer

Leave a comment & ask question