Skip to content

Commit

Permalink
Merge pull request #76 from shivasiddharth/parceltracking-tts
Browse files Browse the repository at this point in the history
added parcel tracking and rss feed streaming
  • Loading branch information
shivasiddharth authored Dec 2, 2017
2 parents 264a77c + ece7ad5 commit f2d5028
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 7 deletions.
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,24 @@
**8. Indicator lights for assistant listening and speaking events.**
**9. Startup audio and audio feedback for wakeword detection.**
**10. Pushbutton service to stop Music or Radio playback.**
**11. Parcel tracking using Aftership API.**
**12. RSS Feed streaming.**

# Features coming soon:
**1. Mute button.**
**2. Blinkt! RGB indicator. (Neopixel is interfering with Pi Audio and I2S so cannot be used without arduino).**


*******************************************************************************************************************************
**Finally !! The project has been update to Python3. This means a better snowboy control and lower CPU utilization on Pi Zero Boards.** **Users who installed GassistPi prior to 12th Nov 2017, please reformat the SD Card and re-install the Assistant to update the project to Python3.**
*******************************************************************************************************************************

*******************************************************************************************************************************
**Existing Python3 GassistPi users, update the project using the script: https://github.com/shivasiddharth/GassistPi/blob/update-script/GassistPi-01-Dec-2017-update.sh**
**New users, folow the instructions in this document.**
*******************************************************************************************************************************


*******************************************************************************************************************************
**CLI or Raspbian Lite does not support all features and Custom wakeword does not work with Google's AIY image. So please use the Standard Raspbian Desktop image- Link https://www.raspberrypi.org/downloads/raspbian/**
*******************************************************************************************************************************
Expand Down Expand Up @@ -258,9 +267,30 @@ http://worldradiomap.com/map/

**Due to the Pi Zero's limitations, users are advised to not use the Radio streaming feature. Radio streaming will send the CPU usage of Pi Zero into next galaxy.**

***********************************************
**FOR PARCEL TRACKING**
***********************************************
The default keyword for tracking parcel is **parcel**. For example, you can say **where is my parcel** or **track my parcel**.

Regsiter for a free account with Aftership at https://www.aftership.com gnereate an API number and add parcels to the tracking list.
The generated API number should be added to the actions.py script at the indicated location. For a better understanding follow the attached youtube video.

<a href="http://www.youtube.com/watch?feature=player_embedded&v=WOyYL46s-q0
" target="_blank"><img src="http://img.youtube.com/vi/WOyYL46s-q0/0.jpg"
alt="Detailed Youtube Video" width="240" height="180" border="10" /></a>

************************************************
**FOR RSS FEEDS**
************************************************
Default keywords for playing RSS feeds is **feed** or **news** or **quote**. Example usage, **top tech news** will play the top technology news, **top world news** will play top news related to different countires, **top sports news** will play the top sports related news and **quote of the day** will give some quotes.

Do not mix the commands with **Play** as that has been associated with music streaming from YouTube.

**numfeeds** variable within the feed function in actions.py file is the feed limit. Certain RSS feeds can have upto 60 items and **numfeeds** variable limits the number of items to stream. The default value has been set to 10, which if you want can change.


************************************************
**FOR NEOPIXEL INDICAOR**
**FOR NEOPIXEL INDICATOR**
************************************************
1. Change the Pin numbers in the given sketch according to your board and upload it.

Expand Down
3 changes: 3 additions & 0 deletions scripts/gassist-installer-pi-zero.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ mpsyt set player vlc, set playerargs ,exit
sudo apt-get install elinks -y
sudo apt-get update -y
sudo apt-get install portaudio19-dev libffi-dev libssl-dev -y
sudo apt-get install libttspico0 libttspico-utils libttspico-data -y
sudo apt-get install python3-dev python3-venv -y
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools
source env/bin/activate
pip install RPi.GPIO
pip install pyaudio
pip install aftership
pip install feedparser
python -m pip install --upgrade google-assistant-sdk
python -m pip install --upgrade google-assistant-sdk[samples]
python -m pip install --upgrade google-auth-oauthlib[tool]
Expand Down
3 changes: 3 additions & 0 deletions scripts/gassist-installer-pi3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,14 @@ sudo apt-get install elinks -y
sudo apt-get update -y
sudo apt-get install python3-dev python3-venv -y
sudo apt-get install portaudio19-dev libffi-dev libssl-dev -y
sudo apt-get install libttspico0 libttspico-utils libttspico-data -y
python3 -m venv env
env/bin/python -m pip install --upgrade pip setuptools
source env/bin/activate
pip install RPi.GPIO
pip install pyaudio
pip install aftership
pip install feedparser
python -m pip install --upgrade google-assistant-library
python -m pip install --upgrade google-assistant-sdk
python -m pip install --upgrade google-assistant-sdk[samples]
Expand Down
115 changes: 109 additions & 6 deletions src/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import time
import re
import subprocess
import aftership
import feedparser

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Expand Down Expand Up @@ -36,35 +38,75 @@
pwm=GPIO.PWM(27, 50)
pwm.start(0)

#Stopbutton
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_UP)

#Led Indicator
GPIO.setup(25, GPIO.OUT)
led=GPIO.PWM(25,1)
led.start(0)

playshell = None

#Parcel Tracking declarations
#If you want to use parcel tracking, register for a free account at: https://www.aftership.com
#Add the API number and uncomment next two lines
#api = aftership.APIv4('YOUR-AFTERSHIP-API-NUMBER')
#couriers = api.couriers.all.get()
number = ''
slug=''

#RSS feed URLS
worldnews = "http://feeds.bbci.co.uk/news/world/rss.xml"
technews = "http://feeds.bbci.co.uk/news/technology/rss.xml"
topnews = "http://feeds.bbci.co.uk/news/rss.xml"
sportsnews = "http://feeds.feedburner.com/ndtvsports-latest"
quote = "http://feeds.feedburner.com/brainyquote/QUOTEBR"


#Text to speech converter
def say(words):
tempfile = "temp.wav"
devnull = open("/dev/null","w")
lang = "en-GB" #Other languages: en-US: US English, en-GB: UK English, de-DE: German, es-ES: Spanish, fr-FR: French, it-IT: Italian
subprocess.call(["pico2wave", "-w", tempfile, "-l", lang, words],stderr=devnull)
subprocess.call(["aplay", tempfile],stderr=devnull)
os.remove(tempfile)

#Radio Station Streaming
def radio(phrase):
for num, name in enumerate(stnname):
if name.lower() in phrase:
station=stnlink[num]
say("Tuning into " + name)
p = subprocess.Popen(["/usr/bin/vlc",station],stdin=subprocess.PIPE,stdout=subprocess.PIPE)

#ESP6266 Devcies control
def ESP(phrase):
for num, name in enumerate(devname):
if name.lower() in phrase:
dev=devid[num]
if 'on' in phrase:
ctrl='=ON'
say("Turning On " + name)
elif 'off' in phrase:
ctrl='=OFF'
say("Turning Off " + name)
subprocess.Popen(["elinks", ip + dev + ctrl],stdin=subprocess.PIPE,stdout=subprocess.PIPE)
time.sleep(2)
subprocess.Popen(["/usr/bin/pkill","elinks"],stdin=subprocess.PIPE)

#Stepper Motor control
def SetAngle(angle):
duty = angle/18 + 2
GPIO.output(27, True)
say("Moving motor by " + str(angle) + " degrees")
pwm.ChangeDutyCycle(duty)
time.sleep(1)
pwm.ChangeDutyCycle(0)
GPIO.output(27, False)

#Play Youtube Music
def YouTube(phrase):
idx=phrase.find('play')
track=phrase[idx:]
Expand All @@ -74,22 +116,83 @@ def YouTube(phrase):
global playshell
if (playshell == None):
playshell = subprocess.Popen(["/usr/local/bin/mpsyt",""],stdin=subprocess.PIPE ,stdout=subprocess.PIPE)

print("Playing: " + track)
say("Playing " + track)
playshell.stdin.write(bytes('/' + track + '\n1\n','utf-8'))
playshell.stdin.flush()

def stop():
pkill = subprocess.Popen(["/usr/bin/pkill","vlc"],stdin=subprocess.PIPE)


#Parcel Tracking
def track():
text=api.trackings.get(tracking=dict(slug=slug, tracking_number=number))
numtrack=len(text['trackings'])
print("Total Number of Parcels: " + str(numtrack))
if numtrack==0:
parcelnotify=("You have no parcel to track")
say(parcelnotify)
elif numtrack==1:
parcelnotify=("You have one parcel to track")
say(parcelnotify)
elif numtrack>1:
parcelnotify=( "You have " + str(numtrack) + " parcels to track")
say(parcelnotify)
for x in range(0,numtrack):
numcheck=len(text[ 'trackings'][x]['checkpoints'])
description = text['trackings'][x]['checkpoints'][numcheck-1]['message']
parcelid=text['trackings'][x]['tracking_number']
trackinfo= ("Parcel Number " + str(x+1)+ " with tracking id " + parcelid + " is "+ description)
say(trackinfo)
#time.sleep(10)

#RSS Feed Reader
def feed(phrase):
if 'world news' in phrase:
URL=worldnews
elif 'top news' in phrase:
URL=topnews
elif 'sports news' in phrase:
URL=sportsnews
elif 'tech news' in phrase:
URL=technews
elif 'my feed' in phrase:
URL=quote
numfeeds=10
feed=feedparser.parse(URL)
feedlength=len(feed['entries'])
print(feedlength)
if feedlength<numfeeds:
numfeeds=feedlength
title=feed['feed']['title']
say(title)
#To stop the feed, press and hold stop button
while GPIO.input(23):
for x in range(0,numfeeds):
content=feed['entries'][x]['title']
print(content)
say(content)
summary=feed['entries'][x]['summary']
print(summary)
say(summary)
if not GPIO.input(23):
break
if x == numfeeds-1:
break
else:
continue



#GPIO Device Control
def Action(phrase):
if 'shut down' in phrase:
subprocess.Popen(["aplay", "/home/pi/GassistPi/sample-audio-files/Pi-Close.wav"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
say('Shutting down Raspberry Pi')
time.sleep(10)
os.system("sudo shutdown -h now")
#subprocess.call(["shutdown -h now"], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if 'servo' in phrase:
if 'motor' in phrase:
for s in re.findall(r'\b\d+\b', phrase):
SetAngle(int(s))
if 'zero' in phrase:
Expand All @@ -100,7 +203,7 @@ def Action(phrase):
pinout=gpio[num]
if 'on' in phrase:
GPIO.output(pinout, 1)
subprocess.Popen(["aplay", "/home/pi/GassistPi/sample-audio-files/Device-On.wav"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
say("Turning On " + name)
elif 'off' in phrase:
GPIO.output(pinout, 0)
subprocess.Popen(["aplay", "/home/pi/GassistPi/sample-audio-files/Device-Off.wav"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
say("Turning Off " + name)
9 changes: 9 additions & 0 deletions src/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
from actions import stop
from actions import radio
from actions import ESP
from actions import track
from actions import feed


try:
from googlesamples.assistant.grpc import (
Expand Down Expand Up @@ -192,6 +195,12 @@ def iter_converse_requests():
if 'wireless'.lower() in str(usrcmd).lower():
ESP(str(usrcmd).lower())
return continue_conversation
if 'parcel'.lower() in str(usrcmd).lower():
track()
return continue_conversation
if 'news'.lower() in str(usrcmd).lower() or 'feed'.lower() in str(usrcmd).lower() or 'quote'.lower() in str(usrcmd).lower():
feed(str(usrcmd).lower())
return continue_conversation
else:
continue
self.logger.info('Transcript of user request: "%s".',
Expand Down
9 changes: 9 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from actions import stop
from actions import radio
from actions import ESP
from actions import track
from actions import feed


GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Expand Down Expand Up @@ -117,6 +120,12 @@ def main():
if 'wireless'.lower() in str(usrcmd).lower():
assistant.stop_conversation()
ESP(str(usrcmd).lower())
if 'parcel'.lower() in str(usrcmd).lower():
assistant.stop_conversation()
track()
if 'news'.lower() in str(usrcmd).lower() or 'feed'.lower() in str(usrcmd).lower() or 'quote'.lower() in str(usrcmd).lower():
assistant.stop_conversation()
feed(str(usrcmd).lower())

if __name__ == '__main__':
main()

0 comments on commit f2d5028

Please sign in to comment.