06_musicPlayer.py 738 B

12345678910111213141516171819202122232425262728
  1. import os
  2. import pyaudio
  3. import wave
  4. import sys
  5. def voice_numberMap(value):
  6. valueScaled = float(value - 0) / float(100)
  7. return valueScaled * 31
  8. while True:
  9. os.system("amixer cset numid=8,iface=MIXER,name='LINEOUT volume'voice_numberMap(25)")
  10. CHUNK = 1024
  11. wf = wave.open(r"/root/preset/audio/funky_stars_quazar.wav", 'rb')#(sys.argv[1], 'rb'
  12. p = pyaudio.PyAudio()
  13. stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),channels=wf.getnchannels(),rate=wf.getframerate(),output=True)
  14. data = wf.readframes(CHUNK)
  15. while len(data) > 0:
  16. stream.write(data)
  17. data = wf.readframes(CHUNK)
  18. stream.stop_stream()
  19. stream.close()
  20. p.terminate()