0

I want to use python to play certain muscial notes depending on some results I obteined erlier in my code. I'm using pydub and I downloaded some .wav sounds in my google colab document. However, I have an error that I can't quit figure out. Here's my code

from pydub import AudioSegment
from pydub.playback import play

note_do = AudioSegment.from_wav(r"/95328__ramas26__c.wav")
note_re = AudioSegment.from_wav(r"/95329__ramas26__d.wav")
note_mi = AudioSegment.from_wav(r"/95330__ramas26__e.wav")
note_fa = AudioSegment.from_wav(r"/95331__ramas26__f.wav")
note_sol = AudioSegment.from_wav(r"/95332__ramas26__g.wav")
note_la = AudioSegment.from_wav(r"/68437__pinkyfinger__piano-a.wav")
note_si = AudioSegment.from_wav(r"/95327__ramas26__b.wav")

for i in range(len(notes_fin)):
  if notes_fin[i]==0:
    play(note_do)
  if notes_fin[i]==1:
    play(note_re)
  if notes_fin[i]==2:
    play(note_mi)
  if notes_fin[i]==3:
    play(note_fa)
  if notes_fin[i]==4:
    play(note_sol)
  if notes_fin[i]==5:
    play(note_la)
  if notes_fin[i]==6:
    play(note_si)

The if statement are based on things I had earlyer in the code. Here's the error I have :

SimpleaudioError                          Traceback (most recent call last)
<ipython-input-39-4842dad5bfc2> in <module>()
     12 for i in range(len(notes_fin)):
     13   if notes_fin[i]==0:
---> 14     play(note_do)
     15   if notes_fin[i]==1:
     16     play(note_re)

2 frames
/usr/local/lib/python3.6/dist-packages/simpleaudio/shiny.py in play_buffer(audio_data, num_channels, bytes_per_sample, sample_rate)
     59 def play_buffer(audio_data, num_channels, bytes_per_sample, sample_rate):
     60     play_id = _sa._play_buffer(audio_data, num_channels, bytes_per_sample,
---> 61                                sample_rate)
     62     return PlayObject(play_id)

SimpleaudioError: Error opening PCM device. -- CODE: -2 -- MSG: No such file or directory

Thank you! :)

Marie
  • 1
  • 1
  • Try to use debug. What's filename that you see? Can you read this file (just read, does not play)? – Mikhail Ionkin Sep 26 '20 at 21:22
  • how do you use debug on a google colab document? :) – Marie Sep 26 '20 at 21:24
  • google is not relevant in this case, because you already download files. It's relevant to your filesystem and filenames. If you see docs, the filename should be present without leading slash – Mikhail Ionkin Sep 26 '20 at 21:29
  • I try putting only the name (e.g : note_do=AudioSegment.from_wav("95328__ramas26__c.wav")), but I still have the seme error... – Marie Sep 26 '20 at 21:39

0 Answers0