Ask coding questions

← Back to all posts
Sounds in Python?
mohaman (0)

How I can use SOUNDS in Python?

Answered by ch1ck3n (2052) [earned 5 cycles]
View Answer
Comments
hotnewtop
poetaetoes (316)
import pysynth

customSong = []
notes = ["c", "d", "e", "f", "g", "a", "b" ]

while True:
  nN = input("Enter a note to add to your song! Press the S key if you are done with the song.\n")
  if nN in notes:
    nL = int(input("Enter the note length\n"))
    note = (nN, nL)
    customSong.append(note)
    
  elif nN == "s":
    pysynth.make_wav(customSong, fn='customSong.wav')
    break
    
  
  

I had this project a while ago, play around with this project. I think you need to create a file with the name that matches the list name and add .wave

ch1ck3n (2052)

@poetaetoes so to play f# i jsut put in f# in the array?

Wumi4 (531)

You can use a module for playing sound, like playsound.

from playsound import playsound
playsound('audio.mp3')