Exemple #1
0
def baidu_record_to_txt(msg):
    try:
        rndstr = StringUtils.buildRandom()
        bsio = BytesIO(msg.get_file())
        audio = AudioSegment.from_mp3(bsio)
        audio2 = audio+6
        export = audio2.export(out_f='amr/%s.amr'%(rndstr),format="amr", bitrate="12.20k")
        bsMp3 = export.read()
        transform = aipSpeech.asr(bsMp3, 'amr', 8000, {'dev_pid': '1536', })

        if transform['err_no'] ==0:
            return  '|'.join(transform['result'])
        else:
            print(transform['err_no'],transform['err_msg'])
    except Exception as er:
        print(er);
Exemple #2
0
def xiaoi_robot(txt,userId='客官'):
    url="http://robot.open.xiaoi.com/ask.do?question=%s&userId=%s&type=0&platform=web"%(txt,userId)

    appKey = "open_oY2gsF6Ueint";
    appSecret = "srAx9cuHDjaFN2N7zw4v";

    str1 = ':'.join( [appKey,'xiaoi.com',appSecret] )
    ha1 = StringUtils.sha1hex(str1)
    ha2 =  StringUtils.sha1hex('GET:/ask.do')
    nonce = StringUtils.buildRandom("",36)

    sig =  StringUtils.sha1hex( ":".join( [ha1,nonce,ha2]) )
    h1={'X-Auth':'app_key="'+appKey+'",nonce="'+nonce+'",signature="'+sig+'"'}

    res = getHtmlText(url,header=h1)
    return res