├── requirements.txt ├── __pycache__ └── app.cpython-39.pyc ├── templates └── index.html └── app.py /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.0.2 2 | SpeechRecognition==3.8.1 3 | pyaudio==0.2.11 -------------------------------------------------------------------------------- /__pycache__/app.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/naveenkumar-42/voice_assistance-/HEAD/__pycache__/app.cpython-39.pyc -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | BIT QUERY SYSTEM 7 | 100 | 101 | 102 | 103 |
104 |

Query System

105 |
106 | 107 | 108 |
109 |
110 |
111 |
112 |
113 |
114 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import random 2 | import pyttsx3 3 | import speech_recognition as sr 4 | from flask import Flask, render_template, request, redirect 5 | 6 | app = Flask(__name__) 7 | 8 | def text_to_speech(text, language='en', voice_gender='f'): 9 | engine = pyttsx3.init() 10 | voices = engine.getProperty('voices') 11 | 12 | # Select voice based on language and gender 13 | if language == 'ta': 14 | if voice_gender == 'm': 15 | voice_id = 'ta+m1' # Replace with the desired Tamil male voice ID 16 | else: 17 | voice_id = 'ta+f1' # Replace with the desired Tamil female voice ID 18 | elif language == 'hi': 19 | if voice_gender == 'm': 20 | voice_id = 'hi+m1' # Replace with the desired Hindi male voice ID 21 | else: 22 | voice_id = 'hi+f1' # Replace with the desired Hindi female voice ID 23 | else: 24 | if voice_gender == 'm': 25 | voice_id = 'en+m3' # Replace with the desired English male voice ID 26 | else: 27 | voice_id = 'en+f3' # Replace with the desired English female voice ID 28 | 29 | # Set the selected voice 30 | selected_voice = None 31 | for voice in voices: 32 | if voice_id in voice.id: 33 | selected_voice = voice 34 | break 35 | 36 | if selected_voice: 37 | engine.setProperty('voice', selected_voice.id) 38 | else: 39 | print(f"Voice not found for voice ID: {voice_id}. Using the default voice.") 40 | 41 | engine.setProperty('rate', 150) # You can adjust the speech rate here 42 | engine.say(text) 43 | engine.runAndWait() 44 | 45 | 46 | def process_query(): 47 | continue_playing = True 48 | language_choice = '' 49 | voice_gender = '' 50 | 51 | while continue_playing: 52 | r = sr.Recognizer() 53 | 54 | if not language_choice: 55 | # Language selection 56 | text_to_speech("Select a language (English, Tamil, Hindi):") 57 | with sr.Microphone() as source: 58 | audio = r.listen(source) 59 | 60 | try: 61 | language_choice = r.recognize_google(audio) 62 | if language_choice.lower() not in ["en", "ta", "hi"]: 63 | language_choice = 'en' 64 | except sr.UnknownValueError: 65 | continue 66 | 67 | if not voice_gender: 68 | # Voice gender selection 69 | text_to_speech("Select a voice gender (male or female):") 70 | with sr.Microphone() as source: 71 | audio = r.listen(source) 72 | 73 | try: 74 | voice_gender = r.recognize_google(audio) 75 | except sr.UnknownValueError: 76 | continue 77 | 78 | text_to_speech("Now you can ask queries.") 79 | 80 | with sr.Microphone() as source: 81 | audio = r.listen(source) 82 | 83 | try: 84 | question = r.recognize_google(audio) 85 | except sr.UnknownValueError: 86 | continue 87 | 88 | if question.lower() == "exit": 89 | break 90 | else: 91 | if "college fees" in question.lower(): 92 | response = "The college fees for Bannari Amman Institute of Technology depend on the course the student has selected." 93 | elif "campus review" in question.lower(): 94 | response = "Bannari Amman Institute of Technology has a sprawling campus with state-of-the-art facilities. The campus provides a conducive environment for learning and offers various amenities to students." 95 | elif "testimonials" in question.lower(): 96 | response = "Bannari Amman Institute of Technology has received positive testimonials from many students and alumni. They appreciate the quality of education, supportive faculty, and the opportunities provided for overall development." 97 | elif "ratings" in question.lower(): 98 | response = "BIT has been rated highly by various ranking agencies and students. It is known for its academic excellence, infrastructure, and placement opportunities." 99 | elif "achievements" in question.lower(): 100 | response = "Bannari Amman Institute of Technology has achieved several accolades in the field of technical education. They have excelled in areas like research, innovation, and industry collaborations." 101 | elif "nirf ranking" in question.lower(): 102 | response = "As of my knowledge cutoff in September 2021, Bannari Amman Institute of Technology was ranked among the top engineering institutes in India by the National Institutional Ranking Framework (NIRF). For the latest ranking information, I recommend checking the NIRF official website." 103 | elif "infrastructure" in question.lower(): 104 | response = "BIT boasts a modern infrastructure with well-equipped laboratories, libraries, sports facilities, hostels, and more. The campus provides a comfortable and conducive environment for learning and extracurricular activities." 105 | elif "location" in question.lower(): 106 | response = "Bannari Amman Institute of Technology is located in Sathyamangalam, Erode district, Tamil Nadu, India. The campus is situated in a serene and scenic environment, offering a peaceful atmosphere for students." 107 | else: 108 | response = "I'm sorry, I don't have the ability to answer that question yet." 109 | 110 | text_to_speech(response, language_choice, voice_gender) 111 | 112 | while True: 113 | text_to_speech("Do you have any other queries? Say 'yes' or 'no'.") 114 | with sr.Microphone() as source: 115 | audio = r.listen(source) 116 | 117 | try: 118 | next_question = r.recognize_google(audio) 119 | 120 | if next_question.lower() == "yes": 121 | break 122 | elif next_question.lower() == "no": 123 | continue_playing = False 124 | break 125 | except sr.UnknownValueError: 126 | continue 127 | 128 | text_to_speech("Thank you for using the query system. Goodbye!") 129 | return redirect('/') 130 | 131 | @app.route('/') 132 | def index(): 133 | return render_template('index.html') 134 | 135 | @app.route('/process', methods=['POST']) 136 | def process(): 137 | return process_query() 138 | 139 | if __name__ == '__main__': 140 | app.run(debug=True) 141 | 142 | --------------------------------------------------------------------------------