您可以使用PyAudio。我的Linux上的一个示例可以正常工作:
#!usr/bin/env python #coding=utf-8import pyaudio import wave#define stream chunk chunk = 1024#open a wav format music f = wave.open(r"/usr/share/sounds/alsa/Rear_Center.wav","rb") #instantiate PyAudio p = pyaudio.PyAudio() #open stream stream = p.open(format = p.get_format_from_width(f.getsampwidth()), channels = f.getnchannels(), rate = f.getframerate(), output = True) #read data data = f.readframes(chunk)#play stream while data: stream.write(data) data = f.readframes(chunk)#stop stream stream.stop_stream() stream.close()#close PyAudio p.terminate()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)