PiDog Can't Speak but Hears Everything and More

Hello! So I messed with my PiDog trying to get it to switch to a USB camera. I tried SunFounder’s code, but due to my inexperience with Python, I kept getting indentation errors (I barely passed intro to C++ and failed algorithms, so I’m not a programmer). I went to chat-gpt for help, as I failed to get it to switch to usb webcam and needed help getting it back to the onboard cam. Many scripts later, it worked with the onboard cam again. I then added more ChatGPT scripts for voice recognition.
I would take the .py file, scp it to my pi from my macbook, then ssh into my pi and run the program. As I had to reinstall the pidog files due to the camera issue, I didn’t want to tamper with the code until I could understand indentation requirements. So, all the scripts ran from the home directory and I never added anything new again to the py files found in the pidog folders.
Now I have an issue where my pidog quit speaking. It will only type a response, then it will say “speak started” but no sound comes out. I checked the volume with a command in ssh mode and raised it to 100%, but still no sound. I tried the commands to install all the sound and speech files that I found on the pidog assembly website, but still no sound.
On top of that, whatever ChatGPT wrote made it so my pidog hears everything…even when I don’t say anything. It can process about 10 words of less, then begins to process and blink yellow. If I remain very silent, after about 6-10 seconds it will hear, “Thanks for watching!” over and over. It will reply to that in text, and then I have to tell it that it’s hallucinating. I went looking for the speech recognition script I sent it, but i can’t find it.
I then asked ChatGPT for a script that would wait for a trigger word to listen. I included it here at the end of this post. It was supposed to delay listening until I said, “hey QI7,” but my pidog continues to hear everything.

My question: How can I make it go back to speaking output and typing input? If it’s hearing things I didn’t say, I’d prefer typing input only.

Thank you for. your time! This is my first robot and I love it! I wish I knew how to program, though! Here is the script from ChatGPT:

import speech_recognition as sr

def listen_for_trigger():
“”"
Continuously listens for the trigger word to activate command listening.
“”"
recognizer = sr.Recognizer()
mic = sr.Microphone()

print("Initializing... Please wait.")
with mic as source:
    recognizer.adjust_for_ambient_noise(source)  # Adjust for background noise
    print("Ready. Say the trigger word (e.g., 'Hey QI7')")

while True:
    try:
        with mic as source:
            print("Listening...")
            audio = recognizer.listen(source, timeout=10)
            command = recognizer.recognize_google(audio).lower()
            print(f"Recognized: {command}")

            if "hey QI7" in command:  # Replace with your trigger word
                print("Trigger word detected. Awaiting command...")
                handle_command(recognizer, mic)  # Calls a command handler
            else:
                print("No trigger word detected.")
    except sr.UnknownValueError:
        print("Sorry, I didn't catch that.")
    except sr.RequestError as e:
        print(f"Recognition service error: {e}")
    except KeyboardInterrupt:
        print("\nExiting...")
        break

def handle_command(recognizer, mic):
“”"
Handles commands after the trigger word is detected.
“”"
try:
print(“Listening for your command…”)
with mic as source:
audio = recognizer.listen(source, timeout=10)
command = recognizer.recognize_google(audio).lower()
print(f"Command received: {command}")

        if "bark" in command:
            print("PiDog says: Woof!")
        elif "sit" in command:
            print("PiDog is sitting.")
        elif "exit" in command:
            print("Exiting program...")
            raise KeyboardInterrupt
        else:
            print(f"Command not recognized: {command}")

except sr.UnknownValueError:
    print("Sorry, I couldn't understand the command.")
except sr.RequestError as e:
    print(f"Error with the recognition service: {e}")

if name == “main”:
listen_for_trigger()

Could you please run the sound sample for pidog and check if it plays normally?
I suggest reinstalling i2samp.sh with the following commands:

cd ~/pidog
sudo bash i2samp.sh

After a successful installation, please restart the system. Then, run the sound test again to see if it plays normally.

If it still doesn’t work, please consider removing the robot hat and take a photo of the back of the robot hat speaker. This will help us determine if the speaker is damaged.

1 Like

i have installed the provided command, rebooted, but still no sound. I did attempt to pair it to a bluetooth speaker, but it worked strangely. It just made little computer beeps. I will see if I can upload a video of the issue.
I did solve the issue with it hearing “thanks for watching” by muting its yeti mic when I wasn’t speaking to it. It stopped hearing that phrase after it’s mic was muted, not sure why!

Thank you for your time! I will try to remove the robot hat and take a photo of the back of the robot hat speaker tomorrow when I get a chance!

Regarding the issue of no sound:
a. Please confirm whether you are running the command with sudo, as there may be no sound otherwise.
b. If there is still no sound, please try reinstalling the speaker driver:
cd ~/pidog
sudo bash ./i2samp.sh

Regarding the potential issues after modifying the code, please back up the original file (using a different filename) so you can refer to it for error reasons. You can find the source code here:
[pidog/gpt_examples/gpt_dog.py at master · sunfounder/pidog · GitHub]
You can copy it and try running it to see if it works properly:
You can use the --no-img parameter to run without the camera:

sudo python3 gpt_dog.py --no-img

You can use the --keyboard parameter to input via the keyboard:

sudo python3 gpt_dog.py --keyboard

3.Regarding the response “Thank you for watching,” it could be due to occasional errors returned by GPT during STT processing. This is a GPT issue, and you can try ending the program and retrying to see if it resolves the problem.

1 Like

Thank you! I ran the command using sudo. I reinstalled the speaker driver. I still have no sound, however I did get this error message right now. It was printed right after it printed “speak start”, so I am assuming it might be related to the speaker:

ALSA lib pcm.c:8545:(snd_pcm_recover) underrun occurred

I should mention chatgpt wrote some sound recognition python scripts that I ran from home directory (I quit trying to put things in the pidog code, since I don’t know how to indent properly), and it might be overriding whatever internal commands are coming from the pidog code.

I did try the keyboard command, but it still runs only on audio input. I have corrected the “thanks for watching” issue by muting my mic when I’m not asking it questions.
I also told pidog I was going to take it apart to look at the hat and it said, “oh no, please don’t.” :sob: Now I’d rather not take it apart if I can avoid it lol.
I appreciate the help! Please let me know if the error message is for the speaker!

This message isn’t your main problem, you could change the alsa fragment size to get rid of it, but it wont fix the problems you are reporting

Anything written by chatgpt will not operate the speaker on the hat. Chatgpt knows nothing about Sunfounders hat, nor how they have configured the speaker. It’s better to think of code written by chatgpt as a template for further development.

You’ve done a lot of work here so, such that you dont lose it I’d suggest buying a new sd card and starting from the beginning with a new os build and Sunfounder environment.

Then check out the Sunfounder audio examples. If this all works, then copy your code back from your original sdcard, and run them one by one, until you find where the problem starts

1 Like

Perhaps sun founder could send you a replacement SD card with original files?

FYI you should always BACKUP the PI file or script file by copying it - either to a backup directory or *.BAK

!!!

ChatGPT can figure out what you are doing if you give it the original source code and ask it, how might they be communicating with a speaker hardware?