Skip to content

Instantly share code, notes, and snippets.

@zitterbewegung
Last active February 11, 2023 20:48
Show Gist options
  • Save zitterbewegung/363f4146fdb9608480631860b263f870 to your computer and use it in GitHub Desktop.
Save zitterbewegung/363f4146fdb9608480631860b263f870 to your computer and use it in GitHub Desktop.
Source code for vocal assistant.
absl-py==0.12.0
appdirs==1.4.4
asgiref==3.3.4
black==21.5b2
cachetools==4.2.2
certifi==2021.5.30
cffi==1.14.6
chardet==4.0.0
click==7.1.2
Django==3.2.3
fastapi==0.65.1
filelock==3.0.12
Flask==2.0.0
google-auth==1.30.1
google-auth-oauthlib==0.4.4
grpcio==1.38.0
h11==0.12.0
huggingface-hub==0.0.12
idna==2.10
itsdangerous==2.0.0
Jinja2==3.0.0
joblib==1.0.1
Markdown==3.3.4
MarkupSafe==2.0.0
mypy-extensions==0.4.3
numpy==1.20.3
oauthlib==3.1.0
packaging==21.0
pathspec==0.8.1
Pillow==8.3.1
protobuf==3.17.1
pyasn1==0.4.8
pyasn1-modules==0.2.8
PyAudio==0.2.11
pycparser==2.20
pydantic==1.8.2
pyobjc==7.3
pyobjc-core==7.3
pyobjc-framework-Accessibility==7.3
pyobjc-framework-Accounts==7.3
pyobjc-framework-AddressBook==7.3
pyobjc-framework-AdServices==7.3
pyobjc-framework-AdSupport==7.3
pyobjc-framework-AppleScriptKit==7.3
pyobjc-framework-AppleScriptObjC==7.3
pyobjc-framework-ApplicationServices==7.3
pyobjc-framework-AppTrackingTransparency==7.3
pyobjc-framework-AuthenticationServices==7.3
pyobjc-framework-AutomaticAssessmentConfiguration==7.3
pyobjc-framework-Automator==7.3
pyobjc-framework-AVFoundation==7.3
pyobjc-framework-AVKit==7.3
pyobjc-framework-BusinessChat==7.3
pyobjc-framework-CalendarStore==7.3
pyobjc-framework-CallKit==7.3
pyobjc-framework-CFNetwork==7.3
pyobjc-framework-ClassKit==7.3
pyobjc-framework-CloudKit==7.3
pyobjc-framework-Cocoa==7.3
pyobjc-framework-Collaboration==7.3
pyobjc-framework-ColorSync==7.3
pyobjc-framework-Contacts==7.3
pyobjc-framework-ContactsUI==7.3
pyobjc-framework-CoreAudio==7.3
pyobjc-framework-CoreAudioKit==7.3
pyobjc-framework-CoreBluetooth==7.3
pyobjc-framework-CoreData==7.3
pyobjc-framework-CoreHaptics==7.3
pyobjc-framework-CoreLocation==7.3
pyobjc-framework-CoreMedia==7.3
pyobjc-framework-CoreMediaIO==7.3
pyobjc-framework-CoreMIDI==7.3
pyobjc-framework-CoreML==7.3
pyobjc-framework-CoreMotion==7.3
pyobjc-framework-CoreServices==7.3
pyobjc-framework-CoreSpotlight==7.3
pyobjc-framework-CoreText==7.3
pyobjc-framework-CoreWLAN==7.3
pyobjc-framework-CryptoTokenKit==7.3
pyobjc-framework-DeviceCheck==7.3
pyobjc-framework-DictionaryServices==7.3
pyobjc-framework-DiscRecording==7.3
pyobjc-framework-DiscRecordingUI==7.3
pyobjc-framework-DiskArbitration==7.3
pyobjc-framework-DVDPlayback==7.3
pyobjc-framework-EventKit==7.3
pyobjc-framework-ExceptionHandling==7.3
pyobjc-framework-ExecutionPolicy==7.3
pyobjc-framework-ExternalAccessory==7.3
pyobjc-framework-FileProvider==7.3
pyobjc-framework-FileProviderUI==7.3
pyobjc-framework-FinderSync==7.3
pyobjc-framework-FSEvents==7.3
pyobjc-framework-GameCenter==7.3
pyobjc-framework-GameController==7.3
pyobjc-framework-GameKit==7.3
pyobjc-framework-GameplayKit==7.3
pyobjc-framework-ImageCaptureCore==7.3
pyobjc-framework-IMServicePlugIn==7.3
pyobjc-framework-InputMethodKit==7.3
pyobjc-framework-InstallerPlugins==7.3
pyobjc-framework-InstantMessage==7.3
pyobjc-framework-Intents==7.3
pyobjc-framework-IOSurface==7.3
pyobjc-framework-iTunesLibrary==7.3
pyobjc-framework-KernelManagement==7.3
pyobjc-framework-LatentSemanticMapping==7.3
pyobjc-framework-LaunchServices==7.3
pyobjc-framework-libdispatch==7.3
pyobjc-framework-LinkPresentation==7.3
pyobjc-framework-LocalAuthentication==7.3
pyobjc-framework-MapKit==7.3
pyobjc-framework-MediaAccessibility==7.3
pyobjc-framework-MediaLibrary==7.3
pyobjc-framework-MediaPlayer==7.3
pyobjc-framework-MediaToolbox==7.3
pyobjc-framework-Metal==7.3
pyobjc-framework-MetalKit==7.3
pyobjc-framework-MetalPerformanceShaders==7.3
pyobjc-framework-MetalPerformanceShadersGraph==7.3
pyobjc-framework-MLCompute==7.3
pyobjc-framework-ModelIO==7.3
pyobjc-framework-MultipeerConnectivity==7.3
pyobjc-framework-NaturalLanguage==7.3
pyobjc-framework-NetFS==7.3
pyobjc-framework-Network==7.3
pyobjc-framework-NetworkExtension==7.3
pyobjc-framework-NotificationCenter==7.3
pyobjc-framework-OpenDirectory==7.3
pyobjc-framework-OSAKit==7.3
pyobjc-framework-OSLog==7.3
pyobjc-framework-PassKit==7.3
pyobjc-framework-PencilKit==7.3
pyobjc-framework-Photos==7.3
pyobjc-framework-PhotosUI==7.3
pyobjc-framework-PreferencePanes==7.3
pyobjc-framework-PushKit==7.3
pyobjc-framework-Quartz==7.3
pyobjc-framework-QuickLookThumbnailing==7.3
pyobjc-framework-ReplayKit==7.3
pyobjc-framework-SafariServices==7.3
pyobjc-framework-SceneKit==7.3
pyobjc-framework-ScreenSaver==7.3
pyobjc-framework-ScreenTime==7.3
pyobjc-framework-ScriptingBridge==7.3
pyobjc-framework-SearchKit==7.3
pyobjc-framework-Security==7.3
pyobjc-framework-SecurityFoundation==7.3
pyobjc-framework-SecurityInterface==7.3
pyobjc-framework-ServiceManagement==7.3
pyobjc-framework-Social==7.3
pyobjc-framework-SoundAnalysis==7.3
pyobjc-framework-Speech==7.3
pyobjc-framework-SpriteKit==7.3
pyobjc-framework-StoreKit==7.3
pyobjc-framework-SyncServices==7.3
pyobjc-framework-SystemConfiguration==7.3
pyobjc-framework-SystemExtensions==7.3
pyobjc-framework-UniformTypeIdentifiers==7.3
pyobjc-framework-UserNotifications==7.3
pyobjc-framework-UserNotificationsUI==7.3
pyobjc-framework-VideoSubscriberAccount==7.3
pyobjc-framework-VideoToolbox==7.3
pyobjc-framework-Virtualization==7.3
pyobjc-framework-Vision==7.3
pyobjc-framework-WebKit==7.3
pyparsing==2.4.7
pyttsx3==2.90
pytz==2021.1
PyYAML==5.4.1
regex==2021.4.4
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7.2
sacremoses==0.0.45
six==1.16.0
snowboy==1.2.0b1
SoundFile==0.10.3.post1
speech-recognition-fork==3.8.1.2021.6.14
SpeechRecognition==3.8.1
sqlparse==0.4.1
starlette==0.14.2
tensorboard==2.5.0
tensorboard-data-server==0.6.1
tensorboard-plugin-wit==1.8.0
tokenizers==0.10.3
toml==0.10.2
torch==1.9.0
torchaudio==0.9.0
torchvision==0.10.0
tqdm==4.61.2
transformers==4.8.2
typing-extensions==3.10.0.0
urllib3==1.26.5
uvicorn==0.13.4
vosk==0.3.30
Werkzeug==2.0.0
#!/usr/bin/env python3
from transformers import pipeline
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import os
import time
import speech_recognition as sr
import pyttsx3
engine = pyttsx3.init()
tokenizer = AutoTokenizer.from_pretrained("facebook/blenderbot-400M-distill")
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/blenderbot-400M-distill")
def GivenCommand(test_mode=False):
Input = ""
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
try:
Input = r.recognize_google(audio, language="english")
print("You: " + Input + "\n")
except sr.UnknownValueError:
talk("Sorry, I didn't understand that. Try typing it here!")
Input = str(input("Command: "))
return Input
def talk(say_this):
print(say_this)
engine = pyttsx3.init()
engine.say(say_this)
engine.runAndWait()
def sentimentAnalysis(utterance: str):
classifier = pipeline('sentiment-analysis')
result = classifier(utterance)
return result
def blenderbot400M(utterance):
inputs = tokenizer([utterance], return_tensors="pt")
reply_ids = model.generate(**inputs)
responses = [
tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True)
for g in reply_ids
]
return responses[0]
if __name__ == "__main__":
while True:
time.sleep(0.1)
Input = GivenCommand()
print("Input {}".format(Input))
Input = Input.lower()
if "goodbye" in Input or "bye" in Input:
talk("Bye, have a great day.")
break
else:
sentiment = sentimentAnalysis(Input)[0].get('label', 'noop')
if sentiment == 'POSITIVE':
talk('You sound POSITIVE ! Yay')
if sentiment == 'NEGATIVE':
talk('You sound NEGATIVE')
response = blenderbot400M(Input)
talk(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment