7. PiDog Speak

PiDog can make sound, it is actually playing a piece of audio.

These audios are saved under pidog\sounds path, you can call the following function to play them.

Pidog.speak(name)
  • name : Filename (without suffix), such as "angry". Pidog provides the following audio.

    • "angry"

    • "confused_1"

    • "confused_2"

    • "confused_3"

    • "growl_1"

    • "growl_2"

    • "howling"

    • "pant"

    • "single_bark_1"

    • "single_bark_2"

    • "snoring"

    • "woohoo"

Here is an example of usage:

# !/usr/bin/env python3
''' play sound effecfs
    Note that you need to run with "sudo"
API:
    Pidog.speak(name, volume=100)
        play sound effecf in the file "../sounds"
        - name    str, file name of sound effect, no suffix required, eg: "angry"
        - volume  int, volume 0-100, default 100
'''
from pidog import Pidog
import os
import time

# change working directory
abspath = os.path.abspath(os.path.dirname(__file__))
# print(abspath)
os.chdir(abspath)

my_dog = Pidog()

print("\033[033mNote that you need to run with \"sudo\", otherwise there may be no sound.\033[m")

# my_dog.speak("angry")
# time.sleep(2)

for name in os.listdir('../sounds'):
    name = name.split('.')[0] # remove suffix
    print(name)
    my_dog.speak(name)
    # my_dog.speak(name, volume=50)
    time.sleep(3) # Note that the duration of each sound effect is different
print("closing ...")
my_dog.close()