Last active
November 19, 2017 13:02
-
-
Save deysumitkr/970e5b4688672bc50f04a2c33716feab to your computer and use it in GitHub Desktop.
python script that says IP address. (Fail safe in case avahi-daemon fails/unusable)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Dependency: | |
Python 2.7 | |
festival (can be downloaded from apt-get)[http://www.cstr.ed.ac.uk/projects/festival/] | |
Raspberry pi audio device select: | |
amixer cset numid=3 0 # auto select (inaccurate) | |
amixer cset numid=3 1 # analog jack 3.5mm | |
amixer cset numid=3 2 # HDMI | |
""" | |
import subprocess | |
def sayThis(text): | |
p = subprocess.Popen(['festival', '--tts'], stdin=subprocess.PIPE) | |
p.communicate(input=text) | |
def getIP(): | |
ips = subprocess.check_output(['hostname', '-I']) | |
return ips.split(' ')[:-1] | |
def sayIP(): | |
ips = getIP() | |
print ips | |
head = 'Number of I P address found is: {0}'.format(len(ips)) | |
sayThis(head) | |
for i in range(len(ips)): | |
toSay = 'I P Address {0} is: {1}'.format(i+1, ips[i]) | |
sayThis(toSay) | |
if __name__ == '__main__': | |
sayIP() | |
# another way with piped execution | |
#~ ps = subprocess.Popen(['hostname', '-I'], stdout=subprocess.PIPE) | |
#~ output = subprocess.call(['festival', '--tts'], stdin=ps.stdout) | |
#~ ps.wait() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment