Audio plays during, but not in codes

the robot hat speakers are not playing any sound at all from my code regardless the code is running well and i also run the example “tts_example” code, it didn’t play the sounds at all except when i run “sudo bash” what should i do?

If you want the robot to sound, you have to run the script to install the components needed for the i2s amplifier, otherwise the robot will have no sound.
You only need to install them once. After that, every time you run the example related to the audio example, it will sound properly.
If you have installed and the robot still does not make sound when running the audio examples, run the script several times.
Or execute the following sudo killall pulseaudio command.