0

I wanted to play a .wav file, without using external modules, and i read i could do that using this:

def play(audio_file_path):
subprocess.call(["ffplay", "-nodisp", "-autoexit", /Users/me/Downloads/sample.wav])

I however get:

SyntaxError: invalid syntax

If i use os.path.realpath to get the absolute path of the file, i get just the same thing. (The path i see at get info)

Environment is OSX, Python 2.7 Can someone tell me what i am doing wrong? I am new to Python (and to Programming).

gsamaras
  • 71,951
  • 46
  • 188
  • 305

1 Answers1

1

There are multiple problems.

  • Indentation
    • Code inside the function should be indented, to show that it is part of the function
  • File name should be in a quotes
    • It should be a string

It should be:

def play(audio_file_path):
    subprocess.call(["ffplay", "-nodisp", "-autoexit", "/Users/me/Downloads/sample.wav"])
matsjoyce
  • 5,744
  • 6
  • 31
  • 38
  • Hi! Thank you so much for answering, that fixed it, but i still do not hear the file play. It is .wav , and i do not get any errors. – Naved Khan Apr 04 '15 at 14:03
  • If you put `ffplay -nodisp -autoexit /Users/me/Downloads/sample.wav` in the terminal, does it work there? – matsjoyce Apr 04 '15 at 14:06
  • NameError: name 'ffplay' is not defined – Naved Khan Apr 04 '15 at 14:08
  • >>> python ffplay -nodisp -autoexit /Users/me/Downloads/sample.wav File "", line 1 python ffplay -nodisp -autoexit /Users/me/Downloads/sample.wav ^ SyntaxError: invalid syntax – Naved Khan Apr 04 '15 at 14:10
  • is it supposed to say "bash" by default? It does, and error is ffplay: command not found – Naved Khan Apr 04 '15 at 14:20
  • @NavedKhan OK, that means that `ffplay` is not installed. Try the instructions at http://www.renevolution.com/how-to-install-ffmpeg-on-mac-os-x/ or try asking at http://apple.stackexchange.com/. – matsjoyce Apr 04 '15 at 14:23
  • @NavedKhan: have you tried [`afplay` instead](http://stackoverflow.com/a/3498622/4279)? – jfs Apr 04 '15 at 22:36