1

[new to stack overflow, don't know how to format. :) ]Trying to make it so when a user inputs something, it plays a sound, something maybe in this format?:

response = input(">>> ")

if response == 0
    #play sound?
PCM
  • 2,881
  • 2
  • 8
  • 30
  • I'm not sure what exactly you want to achieve but here is a similar issue and solution. On every button press on the keyboard a sound is played. Play Sound whenever key is pressed in Python https://stackoverflow.com/questions/62172159/play-sound-whenever-key-is-pressed-in-python – Roadman1991 Nov 18 '21 at 12:42

1 Answers1

1

Use playsound module to play a sound file like .wav or .mp3 (You need to have a sound file downloaded).

Install playsound using cmd with - pip install playsound. More info to install package

After installation, try this basic code to play sound -

from playsound import playsound

response = input(">>> ")
if int(response) == '0':
    playsound('path to sound file')
    print('Playing sound')

This would play the sound file when you type 0 as input

Check this for more info - https://pypi.org/project/playsound/

PCM
  • 2,881
  • 2
  • 8
  • 30