For more details, visit the project repository.
The PDF Query Voice Assistant is a project that allows users to query a PDF document using their voice. The system records an audio query, reduces noise, converts the audio to text, and finds the most relevant response from the PDF document based on the query.
Voice Recording: Record audio queries using the microphone.
Noise Reduction: Reduce background noise from the recorded audio.
Speech Recognition: Convert the cleaned audio into text.
PDF Text Extraction: Extract and clean text from a PDF document.
Similarity Matching: Find the most relevant text in the PDF document that matches the user’s query using cosine similarity.
Main application script to run the voice query process.
Module for recording audio.
Module for reducing noise in the audio.
Module for converting audio to text.
Module for extracting and cleaning text from a PDF document.
Module for calculating cosine similarity and finding the most relevant response.
When prompted, enter the path to the PDF document you want to query.
Path for the Doc: /path/to/your/document.pdf
The application will start recording your query. Press Ctrl+C to stop recording.
The application will process your query and return the most relevant response from the PDF document.
Record Audio: Records audio query and saves it as query.wav.
Reduce Noise: Reduces noise in the recorded audio and saves it as clean_query.wav.
Recognize Speech: Converts the cleaned audio into text.
Extract Text from PDF: Extracts and cleans text from the PDF document.
Find Relevant Response: Finds the most relevant response from the extracted text using cosine similarity.
record_audio(filename, sample_rate=44100): Records audio and saves it to the specified file.
reduce_noise(input_file, output_file): Reduces noise in the input audio file and saves the cleaned audio to the output file.
recognize_speech(audio_file): Converts the audio file to text using Google’s speech recognition API.
extract_text_from_pdf(pdf_path): Extracts raw text from the PDF.
split_into_sentences(text): Splits the text into sentences.
clean_text(text): Cleans the text by removing non-alphanumeric characters.
process_pdf(pdf_path): Processes the PDF to extract and clean text, returning a list of sentences.
cosine_similarity(user_question, comments_list): Calculates cosine similarity between the user’s query and each comment in the list.
return_response(query, pdf_text_list): Finds and returns the most relevant response from the PDF text list based on the query.