Merge branch 'main' of interstellardevelopment.org:sageTheDm/ai-virtual-assistant
This commit is contained in:
commit
a19039d89c
5 changed files with 93 additions and 32 deletions
7
py/static/img/nowifi.svg
Normal file
7
py/static/img/nowifi.svg
Normal file
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff">
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<g id="SVGRepo_iconCarrier"> <path d="M1.33309 8.07433C0.92156 8.44266 0.886539 9.07485 1.25487 9.48638C1.62319 9.89791 2.25539 9.93293 2.66691 9.5646L1.33309 8.07433ZM21.3331 9.5646C21.7446 9.93293 22.3768 9.89791 22.7451 9.48638C23.1135 9.07485 23.0784 8.44266 22.6669 8.07433L21.3331 9.5646ZM12 19C11.4477 19 11 19.4477 11 20C11 20.5523 11.4477 21 12 21V19ZM12.01 21C12.5623 21 13.01 20.5523 13.01 20C13.01 19.4477 12.5623 19 12.01 19V21ZM14.6905 17.04C15.099 17.4116 15.7315 17.3817 16.1031 16.9732C16.4748 16.5646 16.4448 15.9322 16.0363 15.5605L14.6905 17.04ZM18.0539 13.3403C18.4624 13.7119 19.0949 13.682 19.4665 13.2734C19.8381 12.8649 19.8082 12.2324 19.3997 11.8608L18.0539 13.3403ZM7.96372 15.5605C7.55517 15.9322 7.52524 16.5646 7.89687 16.9732C8.2685 17.3817 8.90095 17.4116 9.3095 17.04L7.96372 15.5605ZM4.60034 11.8608C4.19179 12.2324 4.16185 12.8649 4.53348 13.2734C4.90511 13.682 5.53756 13.7119 5.94611 13.3403L4.60034 11.8608ZM10.5705 4.06305C10.0204 4.1118 9.61391 4.59729 9.66266 5.14741C9.71141 5.69754 10.1969 6.10399 10.747 6.05525L10.5705 4.06305ZM17.3393 10.3798C16.8567 10.1114 16.2478 10.285 15.9794 10.7677C15.711 11.2504 15.8847 11.8593 16.3673 12.1277L17.3393 10.3798ZM3.70711 2.29289C3.31658 1.90237 2.68342 1.90237 2.29289 2.29289C1.90237 2.68342 1.90237 3.31658 2.29289 3.70711L3.70711 2.29289ZM20.2929 21.7071C20.6834 22.0976 21.3166 22.0976 21.7071 21.7071C22.0976 21.3166 22.0976 20.6834 21.7071 20.2929L20.2929 21.7071ZM12 6C15.5863 6 18.8556 7.34716 21.3331 9.5646L22.6669 8.07433C19.8369 5.54138 16.0972 4 12 4V6ZM12 21H12.01V19H12V21ZM12 16C13.0367 16 13.9793 16.3931 14.6905 17.04L16.0363 15.5605C14.9713 14.5918 13.5536 14 12 14V16ZM9.3095 17.04C10.0207 16.3931 10.9633 16 12 16V14C10.4464 14 9.02872 14.5918 7.96372 15.5605L9.3095 17.04ZM10.747 6.05525C11.1596 6.01869 11.5775 6 12 6V4C11.5185 4 11.0417 4.0213 10.5705 4.06305L10.747 6.05525ZM16.3673 12.1277C16.9757 12.466 17.5412 12.874 18.0539 13.3403L19.3997 11.8608C18.7751 11.2927 18.0844 10.7941 17.3393 10.3798L16.3673 12.1277ZM2.29289 3.70711L5.46648 6.8807L6.8807 5.46648L3.70711 2.29289L2.29289 3.70711ZM2.66691 9.5646C3.81213 8.53961 5.12648 7.70074 6.56232 7.09494L5.78486 5.25224C4.14251 5.94517 2.64069 6.904 1.33309 8.07433L2.66691 9.5646ZM5.46648 6.8807L9.46042 10.8746L10.8746 9.46042L6.8807 5.46648L5.46648 6.8807ZM9.46042 10.8746L20.2929 21.7071L21.7071 20.2929L10.8746 9.46042L9.46042 10.8746ZM5.94611 13.3403C7.15939 12.2367 8.67355 11.4612 10.3496 11.1508L9.98543 9.18424C7.93271 9.5644 6.08108 10.5139 4.60034 11.8608L5.94611 13.3403Z" fill="#ffffff"/> </g>
|
||||
</svg>
|
After Width: | Height: | Size: 2.9 KiB |
7
py/static/img/wifi.svg
Normal file
7
py/static/img/wifi.svg
Normal file
|
@ -0,0 +1,7 @@
|
|||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
|
||||
<svg width="800px" height="800px" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="#ffffff">
|
||||
<g id="SVGRepo_bgCarrier" stroke-width="0"/>
|
||||
<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
<g id="SVGRepo_iconCarrier"> <path d="M1.33309 8.07433C0.92156 8.44266 0.886539 9.07485 1.25487 9.48638C1.62319 9.89791 2.25539 9.93293 2.66691 9.5646L1.33309 8.07433ZM21.3331 9.5646C21.7446 9.93293 22.3768 9.89791 22.7451 9.48638C23.1135 9.07485 23.0784 8.44266 22.6669 8.07433L21.3331 9.5646ZM12 19C11.4477 19 11 19.4477 11 20C11 20.5523 11.4477 21 12 21V19ZM12.01 21C12.5623 21 13.01 20.5523 13.01 20C13.01 19.4477 12.5623 19 12.01 19V21ZM14.6905 17.04C15.099 17.4116 15.7315 17.3817 16.1031 16.9732C16.4748 16.5646 16.4448 15.9322 16.0363 15.5605L14.6905 17.04ZM18.0539 13.3403C18.4624 13.7119 19.0949 13.682 19.4665 13.2734C19.8381 12.8649 19.8082 12.2324 19.3997 11.8608L18.0539 13.3403ZM7.96372 15.5605C7.55517 15.9322 7.52524 16.5646 7.89687 16.9732C8.2685 17.3817 8.90095 17.4116 9.3095 17.04L7.96372 15.5605ZM4.60034 11.8608C4.19179 12.2324 4.16185 12.8649 4.53348 13.2734C4.90511 13.682 5.53756 13.7119 5.94611 13.3403L4.60034 11.8608ZM2.66691 9.5646C5.14444 7.34716 8.41371 6 12 6V4C7.90275 4 4.16312 5.54138 1.33309 8.07433L2.66691 9.5646ZM12 6C15.5863 6 18.8556 7.34716 21.3331 9.5646L22.6669 8.07433C19.8369 5.54138 16.0972 4 12 4V6ZM12 21H12.01V19H12V21ZM12 16C13.0367 16 13.9793 16.3931 14.6905 17.04L16.0363 15.5605C14.9713 14.5918 13.5536 14 12 14V16ZM12 11C14.3319 11 16.4546 11.8855 18.0539 13.3403L19.3997 11.8608C17.4466 10.0842 14.8487 9 12 9V11ZM9.3095 17.04C10.0207 16.3931 10.9633 16 12 16V14C10.4464 14 9.02872 14.5918 7.96372 15.5605L9.3095 17.04ZM5.94611 13.3403C7.54544 11.8855 9.66815 11 12 11V9C9.15127 9 6.55344 10.0842 4.60034 11.8608L5.94611 13.3403Z" fill="#ffffff"/> </g>
|
||||
</svg>
|
After Width: | Height: | Size: 2 KiB |
|
@ -157,7 +157,11 @@ header a:hover {
|
|||
}
|
||||
|
||||
.models form {
|
||||
padding: 0;
|
||||
padding-right: 10px;
|
||||
padding-left: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.models .titel {
|
||||
|
@ -171,6 +175,7 @@ header a:hover {
|
|||
display: grid;
|
||||
grid-template-columns: repeat(2, 1fr);
|
||||
gap: 1.5vh;
|
||||
width: fit-content;
|
||||
/* height: calc(100% - 2em); */
|
||||
}
|
||||
|
||||
|
@ -188,7 +193,6 @@ header a:hover {
|
|||
position: relative;
|
||||
height: 18vh;
|
||||
width: 18vh;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.overlay {
|
||||
|
@ -210,6 +214,16 @@ header a:hover {
|
|||
font-size: xx-large;
|
||||
}
|
||||
|
||||
.overlay img {
|
||||
align-self: flex-end;
|
||||
justify-self: end;
|
||||
height: 3vh;
|
||||
width: 3vh;
|
||||
position: absolute;
|
||||
right: 15px;
|
||||
bottom: 15px;
|
||||
}
|
||||
|
||||
.model-box:hover .overlay {
|
||||
opacity: 1;
|
||||
}
|
||||
|
@ -441,13 +455,14 @@ header a:hover {
|
|||
|
||||
::-webkit-scrollbar {
|
||||
width: 7px;
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-track {
|
||||
background-color: var(--scrollbar-track);
|
||||
border-radius: 5px;
|
||||
overflow: hidden;
|
||||
margin-left: 10px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
::-webkit-scrollbar-thumb {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<link rel="stylesheet" href="styles.css" />
|
||||
<link rel="stylesheet" href="/static/styles.css" />
|
||||
<title>AI Assistant</title>
|
||||
</head>
|
||||
|
||||
|
@ -71,11 +71,13 @@
|
|||
<button class="code-model model-box">
|
||||
<div class="overlay">
|
||||
<h3>Code</h3>
|
||||
<img src="/static/img/wifi.svg" alt="Wi-Fi" />
|
||||
</div>
|
||||
</button>
|
||||
<button class="math-model model-box">
|
||||
<div class="overlay">
|
||||
<h3>Math</h3>
|
||||
<img src="/static/img/nowifi.svg" alt="No Wi-Fi" />
|
||||
</div>
|
||||
</button>
|
||||
<button class="language-model model-box">
|
||||
|
|
|
@ -1,31 +1,61 @@
|
|||
import speech_recognition as sr
|
||||
#pip install faster-whisper
|
||||
from api import API
|
||||
import os
|
||||
import wave
|
||||
from faster_whisper import WhisperModel
|
||||
import pyaudio
|
||||
|
||||
class Voice: #create Class
|
||||
@staticmethod
|
||||
def listen(): #define function listen()
|
||||
recognizer = sr.Recognizer()
|
||||
def transcribe_chunk(model, file_path):
|
||||
print("transcribing...")
|
||||
segments, _ = model.transcribe(file_path)
|
||||
transcription = ""
|
||||
for segment in segments:
|
||||
transcription += segment.text + " "
|
||||
return transcription.strip()
|
||||
|
||||
try:
|
||||
with sr.Microphone() as source:
|
||||
print("Adjusting for ambient noise...")
|
||||
recognizer.adjust_for_ambient_noise(source, duration=0.5) #listen to surrounding for .5sec to adjust backgroundnoise
|
||||
print("Listening...")
|
||||
audio_data = recognizer.listen(source) #listen to user until user stops speaking
|
||||
print("Audio captured")
|
||||
try:
|
||||
text = recognizer.recognize_sphinx(audio_data) # Using Sphinx convert audio to text (also works offline)
|
||||
#if any Exceptions or Errors eccur => return ERROR
|
||||
except sr.UnknownValueError:
|
||||
text = "ERROR"
|
||||
except sr.RequestError as e:
|
||||
text = "ERROR"
|
||||
#Record voice
|
||||
#chunk_length = duration to record in seconds
|
||||
def record_chunk(p, stream, file_path, chunk_length=2):
|
||||
frames=[]
|
||||
for _ in range(0, int(16000/1024 * chunk_length)):
|
||||
data = stream.read(1024)
|
||||
frames.append(data)
|
||||
|
||||
except sr.RequestError as e:
|
||||
text = "ERROR"
|
||||
except sr.UnknownValueError:
|
||||
text = "ERROR"
|
||||
except Exception as e:
|
||||
text = "ERROR"
|
||||
return text
|
||||
wf = wave.open(file_path, 'wb')
|
||||
wf.setnchannels(1)
|
||||
wf.setsampwidth(p.get_sample_size(pyaudio.paInt16))
|
||||
wf.setframerate(16000)
|
||||
wf.writeframes(b''.join(frames))
|
||||
wf.close()
|
||||
|
||||
def listen():
|
||||
#model settings (tiny, base, small, medium, large)
|
||||
model_size = "medium"
|
||||
#what should it run on (cpu or cuda for gpu)
|
||||
model = WhisperModel(model_size, device="cpu", compute_type="int8")
|
||||
|
||||
p = pyaudio.PyAudio()
|
||||
stream = p.open(format=pyaudio.paInt16, channels=1, rate = 16000, input = True, frames_per_buffer=1024)
|
||||
|
||||
try:
|
||||
while True:
|
||||
print("Recording...")
|
||||
# CHANGE TEMP FILE PATH
|
||||
chunk_file="temp_chunk.wav"
|
||||
record_chunk(p, stream, chunk_file)
|
||||
transcription = transcribe_chunk(model, chunk_file)
|
||||
print(transcription)
|
||||
try:
|
||||
return transcription
|
||||
except Exception as e:
|
||||
return "ERROR"
|
||||
finally:
|
||||
if os.path.exists(chunk_file):
|
||||
os.remove(chunk_file)
|
||||
break
|
||||
except KeyboardInterrupt:
|
||||
print("Stopping...")
|
||||
finally:
|
||||
stream.stop_stream()
|
||||
stream.close()
|
||||
p.terminate()
|
Loading…
Reference in a new issue