JaganathC commited on
Commit
603e888
·
1 Parent(s): 5ba9001

Upload 8 files

Browse files
Files changed (9) hide show
  1. .gitattributes +1 -0
  2. .gitignore +3 -0
  3. LICENSE +21 -0
  4. Procfile +1 -0
  5. README.md +72 -12
  6. app.py +89 -0
  7. prompt.wav +0 -0
  8. requirements.txt +44 -0
  9. wake_detect.wav +3 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ wake_detect.wav filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ # .gitignore
2
+ venv
3
+ __pycache__
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Ashutosh
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Procfile ADDED
@@ -0,0 +1 @@
 
 
1
+ web: gunicorn app:app
README.md CHANGED
@@ -1,12 +1,72 @@
1
- ---
2
- title: VoiceAssistance
3
- emoji: 📈
4
- colorFrom: gray
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 3.41.1
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1 align="center">Bard Voice Assistant Web Application😃</h1>
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ https://github.com/Ghost-Ashu/Bard-Voice-Assistant/assets/41056892/af6bd22c-4b81-4ad3-9784-d64e2e11bceb
11
+
12
+
13
+
14
+
15
+
16
+ <p align="center">
17
+ <strong>A Flask web application that provides a user interface to interact with a chatbot.</strong>
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="#installation">Installation</a> •
22
+ <a href="#usage">Usage</a> •
23
+ <a href="#license">License</a>
24
+ </p>
25
+
26
+ ## Installation
27
+
28
+ <ol>
29
+ <li>Clone the repository:
30
+ <pre><code>git clone https://github.com/your-username/your-repository.git
31
+ cd your-repository</code></pre>
32
+ </li>
33
+
34
+ <li>Create a virtual environment (optional but recommended):
35
+ <pre><code>python3 -m venv venv
36
+ source venv/bin/activate</code></pre>
37
+ </li>
38
+
39
+ <li>Install the dependencies:
40
+ <pre><code>pip install -r requirements.txt</code></pre>
41
+ </li>
42
+
43
+ <li>Obtain a Bard Token:
44
+ <ul>
45
+ <li>Sign up on the <a href="https://www.bard.ai/">Bard</a> website to get an API token.</li>
46
+ <li>Replace the <code>token</code> variable in <code>app.py</code> with your token.</li>
47
+ </ul>
48
+ </li>
49
+
50
+ <li>Download Whisper models:
51
+ <ul>
52
+ <li>Download the <code>tiny</code> and <code>base</code> models from the <a href="https://github.com/snakers4/whisper">Whisper</a> repository.</li>
53
+ <li>Place the models in the same directory as <code>app.py</code>.</li>
54
+ </ul>
55
+ </li>
56
+
57
+ <li>Run the application:
58
+ <pre><code>python app.py</code></pre>
59
+ </li>
60
+
61
+ <li>Open your web browser and visit <code>http://localhost:5000</code> to access the chatbot interface.</li>
62
+ </ol>
63
+
64
+ ## Usage
65
+
66
+ - Enter text input: Type your message in the input field and press Enter or click the "Send" button. The chatbot will respond accordingly.
67
+ - Speech input: Click the "Listen" button and speak your prompt to the chatbot. It will transcribe your speech, send it to the chatbot, and provide a spoken response.
68
+ - Speech output: Enter your prompt in the input field and click the "Speak" button. The chatbot's response will be spoken aloud.
69
+
70
+ ## License
71
+
72
+ This project is licensed under the <a href="LICENSE">MIT License</a>.
app.py ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request, jsonify
2
+ from Bard import Chatbot
3
+ import pyttsx3
4
+ import speech_recognition as sr
5
+ import whisper
6
+
7
+ app = Flask(__name__, static_folder='static', template_folder='templates')
8
+
9
+ # Paste your Bard Token (check README.md for where to find yours)
10
+ token = "<ADD YOUR BARD SESSION TOKEN>"
11
+ # Initialize Google Bard API
12
+ chatbot = Chatbot(token)
13
+ # Initialize speech recognition
14
+ r = sr.Recognizer()
15
+ # Initialize Whisper model
16
+ tiny_model = whisper.load_model('tiny')
17
+ base_model = whisper.load_model('base')
18
+
19
+ # Initialize pyttsx3 for text-to-speech
20
+ engine = pyttsx3.init()
21
+ # Get the current speech rate
22
+ rate = engine.getProperty('rate')
23
+ # Decrease speech rate by 50 words per minute (Change as desired)
24
+ engine.setProperty('rate', rate - 50)
25
+
26
+
27
+ def prompt_bard(prompt):
28
+ response = chatbot.ask(prompt)
29
+ return response['content']
30
+
31
+
32
+ def speak(text):
33
+ engine.say(text)
34
+ engine.runAndWait()
35
+
36
+
37
+ def listen_for_prompt():
38
+ with sr.Microphone() as source:
39
+ try:
40
+ print("Speak your prompt to Bard.\n")
41
+ # Record prompt
42
+ audio = r.listen(source)
43
+ with open("prompt.wav", "wb") as f:
44
+ f.write(audio.get_wav_data())
45
+ # Transcribe prompt using whisper base model
46
+ result = base_model.transcribe('prompt.wav')
47
+ prompt_text = result['text']
48
+ print("Sending to Bard:", prompt_text, '\n')
49
+ # If prompt is empty, return empty response
50
+ if len(prompt_text.strip()) == 0:
51
+ return ""
52
+ return prompt_text
53
+ except Exception as e:
54
+ print("Error transcribing audio: ", e)
55
+ return ""
56
+
57
+
58
+ @app.route('/')
59
+ def index():
60
+ return render_template('index.html')
61
+
62
+
63
+ @app.route('/ask', methods=['POST'])
64
+ def ask():
65
+ prompt = request.form['prompt']
66
+ response = prompt_bard(prompt)
67
+ return jsonify({'response': response})
68
+
69
+
70
+ @app.route('/speak', methods=['POST'])
71
+ def speak_prompt():
72
+ prompt = request.form['prompt']
73
+ speak(prompt)
74
+ return jsonify({'status': 'success'})
75
+
76
+
77
+ @app.route('/listen', methods=['POST'])
78
+ def listen_prompt():
79
+ prompt = listen_for_prompt()
80
+ if prompt:
81
+ response = prompt_bard(prompt)
82
+ speak(response)
83
+ return jsonify({'response': response})
84
+ else:
85
+ return jsonify({'response': 'No prompt recorded.'})
86
+
87
+
88
+ if __name__ == '__main__':
89
+ app.run(debug=True)
prompt.wav ADDED
Binary file (264 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ blinker==1.6.2
2
+ certifi==2023.5.7
3
+ charset-normalizer==3.1.0
4
+ click==8.1.3
5
+ colorama==0.4.6
6
+ comtypes==1.2.0
7
+ ffmpeg-python==0.2.0
8
+ filelock==3.12.2
9
+ Flask==2.3.2
10
+ future==0.18.3
11
+ GoogleBard==0.0.7
12
+ gunicorn==20.1.0
13
+ heroku==0.1.4
14
+ idna==3.4
15
+ itsdangerous==2.1.2
16
+ Jinja2==3.1.2
17
+ llvmlite==0.40.1rc1
18
+ markdown-it-py==3.0.0
19
+ MarkupSafe==2.1.3
20
+ mdurl==0.1.2
21
+ more-itertools==9.1.0
22
+ mpmath==1.3.0
23
+ networkx==3.1
24
+ numba==0.57.0
25
+ numpy==1.24.3
26
+ openai-whisper==20230314
27
+ prompt-toolkit==3.0.38
28
+ Pygments==2.15.1
29
+ pypiwin32==223
30
+ python-dateutil==1.5
31
+ pyttsx3==2.90
32
+ pywin32==306
33
+ regex==2023.6.3
34
+ requests==2.31.0
35
+ rich==13.4.2
36
+ SpeechRecognition==3.10.0
37
+ sympy==1.12
38
+ tiktoken==0.3.1
39
+ torch==2.0.1
40
+ tqdm==4.65.0
41
+ typing_extensions==4.6.3
42
+ urllib3==2.0.3
43
+ wcwidth==0.2.6
44
+ Werkzeug==2.3.6
wake_detect.wav ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cccf3ffdc78f000d45dc15c2f3a18801f81c71e7689c58b9ec1a59d5f347ddce
3
+ size 2785324