zoukankan      html  css  js  c++  java
  • testAPI

    #!coding:utf-8
    import urllib
    import json
    import base64
    import os
    import time
    
    
    def getToken():
        Api_Key = 'hSCATgTQCvoE50cvNOkM37wm'
        Secrect_Key = '969430e14e7a654a89bf32aa63654346'
        url = 'https://openapi.baidu.com/oauth/2.0/token?grant_type=client_credentials&client_id=' + Api_Key + '&client_secret=' + Secrect_Key
    
        res = urllib.urlopen(url).read()
        data = json.loads(res)
        token = data['access_token']  # 获取的token
        print 'token获取成功:', token
        return token
    
    
    def getYuYin(token, text):
        data = {'tex': text, 'lan': 'zh', 'cuid': '68-07-15-92-7C-2D', 'ctp': '1',
                'spd': '4', 'vol': '8',
                'tok': token}
        date_urlencode = urllib.urlencode(data)
        print date_urlencode
        ServerUrl = 'http://tsn.baidu.com/text2audio'
        r = urllib.urlopen(ServerUrl, str.encode(date_urlencode))
        print r.getcode()
        result = r.read()
        file = open(r"voice.mp3", "wb")
        file.write(result)
        file.close()
    
    
    token = getToken()
    text = '你好我叫吴建豪,事件号IM12343发生故障,请及时处理,Jean,please finish it.'
    getYuYin(token, text)
    
    
  • 相关阅读:
    D. Constructing the Array
    B. Navigation System
    B. Dreamoon Likes Sequences
    A. Linova and Kingdom
    G. Special Permutation
    B. Xenia and Colorful Gems
    Firetrucks Are Red
    java getInstance()的使用
    java 静态代理和动态代理
    java 类加载机制和反射机制
  • 原文地址:https://www.cnblogs.com/jian-pan/p/testAPI.html
Copyright © 2011-2022 走看看