I am running a main script on windows 10 that calls another script called audioplayer.py using the subprocess
module in python.
I want to send some input arguments when calling the audioplayer.py. So I wrote the main script as follows:
The following is the main script:
from subprocess import call
call(["python", "C:/Users/Jeff/Documents/audioplayer.py", "hey.wav"])
The following is my audioplayer.py:
"""OpenAL playback example."""
import os, sys, time
from openal.audio import SoundSink, SoundSource
from openal.loaders import load_wav_file
if len (sys.argv) < 2:
print ("Usage: %s wavefile" % os.path.basename(sys.argv[0]))
print (" Using an example wav file...")
dirname = os.path.dirname(__file__)
fname = os.path.join(dirname, "default.wav")
else:
fname = sys.argv[1]
sink = SoundSink()
sink.activate()
source = SoundSource(position=[10, 0, 0])
source.looping = True
data = load_wav_file(fname)
source.queue(data)
sink.play(source)
source.position = [source.position[0], source.position[1], source.position[2]]
sink.update()
time.sleep(2)
print("playing at %r" % source.position)
But I keep getting the following error even though the file does exist in the same directory as audioplayer.py
FileNotFoundError: [Errno 2] No such file or directory: 'hey.wav'
If I remove the hey.wav
in the main script, it runs fine. It just doesn't seem to take any arguments.
try this:
call(["python", "C:/Users/Jeff/Documents/audioplayer.py", "C:/Users/Jeff/Documents/hey.wav"])
When you run the last one, the dir is the same with the main.py instead of the audioplayer.py.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.