为了小孩多听粤语,想播放以前收音机里面的小说节目,于是做了一个这样的东西, 每天定时大约吃饭时间播放一集节目, 第一季节目就播三国演义把.
垃圾电视盒刷armbian, 接usb 声卡, 一个功放模块,一个控制模块, 三个模块都是自己做了, 控制模块是usb转串口,接一个单片机,控制功放模块的电源, 因为24小时不停待机,因此不播放的时候要休眠状态.
垃圾电视盒是没有IO的,所以有这个东西.
安装所有必须的东西
samba, cifs-utils , 音频文件在nas上,所以要装samba 共享.
stty,控制串口波特率等
sox , 播放mp3的的东西
apt-get install libsox-fmt-all  支持mp3
python, 控制脚本
python 脚本
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
   | #!/usr/bin/python
  import json import os import linecache import sys
 
 
  filename = 'cur_play_id.json' list_name = 'play_list' index=1
 
  os.system('stty -F /dev/ttyUSB0 115200') os.system ('echo ":9000020101aa\r\n" >> /dev/ttyUSB0') os.system ('play sanya.mp3')
  if len(sys.argv)  > 1  :     list_name= sys.argv[1]    print(list_name)
 
 
  try:
      with open (filename) as f_obj:         ja=json.load(f_obj)         index=ja['cur_index']         index = index +1
  except FileNotFoundError:     print("index file Not Found!@!!!")     index = 1
 
  try:
      play_file = linecache.getline(list_name,index).strip()     if play_file =='' :         print ("end of play list file")     else :         a_cmd = 'play ' + play_file         print(a_cmd)         os.system(a_cmd)         os.system ('echo ":9000020100aa\r\n" >> /dev/ttyUSB0')
  except FileNotFoundError:     print ("Play List file not found!!")     os._exit(0)
 
 
  data_dic = {'cur_index':index}
  with open(filename,'w') as f:     json.dump(data_dic,f)
 
 
 
   | 
 
用法就是python play_mp3.py list.txt
生成播放列表文件的脚本
1
   | ls -1 |awk '{print i$0}' i=`pwd`'/' > list.txt
  |