Quiz game project using speech recognition
About project:
This Python project that creates a quiz game with speech
recognition using the speech_recognition library. The game
asks multiple-choice questions, and players answer by speaking
into the microphone. highlights how to incorporate speech
recognition to make an interactive and accessible quiz game.
Libraries used ,
1]Speech Recognition:
. It capture and recognize the spoken answers.
. Then it convert the spoken answers into text format.
Note: It requires the active internet connection and functioning
microphone.
Source :Functioning Microphone
2]Time:
time.sleep() - is used to suspends execution for specific time .
(Eg) time.sleep(20)
1.Questions and Options:
The game include questions stored in the questions tuple.
Each question has four options, stored in the options
tuple. Each answer is represented by a letter, like “A” or
“B,” stored in the answers list.
2.Speech Recognition:
The recognize_speech() function listens for audio input through
the microphone, converts it to text using Google’s speech
recognition service, and returns it in uppercase to match the
format of the answer options.
Program:
recognizer = sr.Recognizer() with
sr.Microphone() as source: audio =
recognizer.listen(source)
If the recognition fails (e.g., due to background noise or a
network issue), it handles errors and prompts the user
accordingly.
Program:
except sr.UnknownValueError:
print("Sorry, I did not understand that.")
return "" except sr.RequestError:
print("Sorry, I could not reach the speech recognition
service.")
return ""
3.Game Flow:
For each question, the game displays the question and options.
The second question is a “multiple select” type, allowing for
multiple answers, so extra formatting is applied by removing
spaces in the user’s spoken response.
After the player speaks their answer, it’s compared to the
correct answer.
If correct, it increments the score and provides feedback. If
incorrect, it shows the correct answer.
4.Results:
At the end, it displays the user’s guesses, correct answers, the
score, and the percentage score.