text: #-*- coding: utf-8 -*-
  import requests
  import time
  import hashlib
  import base64
  
  URL = "http://openapi.xfyun.cn/v2/aiui"
  APPID = "5d2f27d2"
  API_KEY = "a605c4712faefae730cc84b62c0eb92f"
  AUE = "raw"
  AUTH_ID = "f9be5221d3288ef324aeb1a0ce73abcd"
  DATA_TYPE = "audio"
  SAMPLE_RATE = "16000"
  SCENE = "main_box"
  RESULT_LEVEL = "complete"
  LAT = "39.938838"
  LNG = "116.368624"
  #个性化参数，需转义
  PERS_PARAM = "{\\\"auth_id\\\":\\\"f9be5221d3288ef324aeb1a0ce73abcd\\\"}"
  FILE_PATH = "output.wav"
  
  
  def buildHeader():
      curTime = str(int(time.time()))
      param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"scene\":\""+SCENE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\"}"
      #使用个性化参数时参数格式如下：
      #param = "{\"result_level\":\""+RESULT_LEVEL+"\",\"auth_id\":\""+AUTH_ID+"\",\"data_type\":\""+DATA_TYPE+"\",\"sample_rate\":\""+SAMPLE_RATE+"\",\"scene\":\""+SCENE+"\",\"lat\":\""+LAT+"\",\"lng\":\""+LNG+"\",\"pers_param\":\""+PERS_PARAM+"\"}"
      paramBase64 = base64.b64encode(param.encode('utf-8'))
      paramBase64 = paramBase64.decode('utf-8')
      m2 = hashlib.md5()
      m2.update((API_KEY + curTime + paramBase64).encode('utf-8'))
      checkSum = m2.hexdigest()
  
      header = {
          'X-CurTime': curTime,
          'X-Param': paramBase64,
          'X-Appid': APPID,
          'X-CheckSum': checkSum,
      }
      return header
  
  def readFile(filePath):
      binfile = open(filePath, 'rb')
      data = binfile.read()
      return data
  
  def getText(fname):
      r = requests.post(URL, headers=buildHeader(), data=readFile(fname))
      print(r.content)
      return r.content