• 百度AI


    1.语音合成

    1.登录百度AI平台

    选择控制台

    参考技术文档选择python SDK

    pip install baidu-aip
    
    from aip import AipSpeech
    
    APP_ID = '2191211'
    API_KEY = 'tQ1f7pryTnMjQMfuYGL8'
    SECRET_KEY = 'M70i1KwVfYgKZLY0pvl3LKGtTYg'
    
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    
    result = client.synthesis('先帝创业未半而中道崩殂', 'zh', 1,
                              {
                                  'vol': 5,
                                  "spd": 4,
                                  "pit": 6,
                                  "per": 4
                              })
    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        with open('aui2do.mp3', 'wb') as f:
            f.write(result)
    else:
        print(result)
    

    2.语音识别

    from aip import AipSpeech
    
    APP_ID = '21411'
    API_KEY = 'tQ1f7prynKMjQMfuYGL8'
    SECRET_KEY = 'M70i1KwVfYgKZpEnGvl3LKGtTYg'
    
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    
    # 读取文件
    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()
    
    # 识别本地文件
    res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
        'dev_pid': 1537,
    })
    print(res['result'][0])
    

    3.智障对话

    1.low版本

    from aip import AipSpeech
    import  os
    
    APP_ID = '21911'
    API_KEY = 'tQ1f7pryTnKMQMfuYGL8'
    SECRET_KEY = 'M70i1KgKZYr0pE5nGvl3LKGtTYg'
    
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    
    # 读取文件
    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()
    
    # 识别本地文件
    res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
        'dev_pid': 1537,
    })
    Q = res['result'][0]
    A = "我不知道"
    if Q == "你的名字叫什么?":
        A = "zbb"
    result = client.synthesis(A, 'zh', 1,
                              {
                                  'vol': 5,
                                  "spd": 4,
                                  "pit": 6,
                                  "per": 4
                              })
    
    if not isinstance(result, dict):
        with open('aui2do.mp3', 'wb') as f:
            f.write(result)
    else:
        print(result)
    
    os.system("aui2do.mp3")
    

    2.升级版

    自然语言处理

    from aip import AipSpeech
    from aip import AipNlp
    import os
    
    APP_ID = '22411'
    API_KEY = 'tQ1f7pryTnd8MfuYGL8'
    SECRET_KEY = 'M70i1KwVfYK0pE5nGvl3LKGtTYg'
    
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    
    nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
    
    
    # 读取文件
    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()
    
    
    # 识别本地文件
    res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
        'dev_pid': 1537,
    })
    Q = res['result'][0]
    A = "我是你爸爸"
    if nlp_client.simnet(Q, "你的名字叫什么?")['score'] > 0.6:
        A = "你是我儿子"
    
    result = client.synthesis(A, 'zh', 1,
                              {
                                  'vol': 5,
                                  "spd": 4,
                                  "pit": 6,
                                  "per": 4
                              })
    
    if not isinstance(result, dict):
        with open('aui2do.mp3', 'wb') as f:
            f.write(result)
    else:
        print(result)
    
    os.system("aui2do.mp3")
    

    3.加强版

    问答机器人 -图灵机器人

    import requests
    
    res = requests.post(url='http://openapi.tuling123.com/openapi/api/v2', json={
        "reqType": 0,
        "perception": {
            "inputText": {
                "text": "青岛的天气"
            },
        },
        "userInfo": {
            "apiKey": "9ea379299a91354e0fe979ad",
            "userId": "6542"
        }
    })
    print(res.json()['results'][0]['values']['text'])
    #青岛:周二 08月11日,多云转小雨 南风,最低气温25度,最高气温28度。~
    

    4.进化版

    from aip import AipSpeech
    from aip import AipNlp
    import os
    import requests
    
    APP_ID = '212411'
    API_KEY = 'tQ1f7prTnd8jQMfuYGL8'
    SECRET_KEY = 'M70i1KwVfYr0'
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    nlp_client = AipNlp(APP_ID, API_KEY, SECRET_KEY)
    
    
    # 读取文件
    def get_file_content(filePath):
        with open(filePath, 'rb') as fp:
            return fp.read()
    
    
    # 识别本地文件
    res = client.asr(get_file_content('wyn.m4a.pcm'), 'pcm', 16000, {
        'dev_pid': 1537,
    })
    Q = res['result'][0]
    
    if nlp_client.simnet(Q, "附近的酒单?")['score'] > 0.6:
        A = "你是我儿子"
    
    else:
        res = requests.post(url='http://openapi.tuling123.com/openapi/api/v2', json={
            "reqType": 0,
            "perception": {
                "inputText": {
                    "text": Q
                },
            },
            "userInfo": {
                "apiKey": "9ea379299354e979ad",
                "userId": "654562"
            }
        })
        A =  res.json()['results'][0]['values']['text']
    result = client.synthesis(A, 'zh', 1,
                              {
                                  'vol': 5,
                                  "spd": 4,
                                  "pit": 6,
                                  "per": 4
                              })
    
    if not isinstance(result, dict):
        with open('aui2do.mp3', 'wb') as f:
            f.write(result)
    else:
        print(result)
    
    os.system("aui2do.mp3")
    

    5.究极版

    科大讯飞 语音最强没有之一(当然图片识别啥的好烂。。。)

  • 相关阅读:
    IE和FireFox兼容问题(一)zt
    FireFox不支持.style.cssText
    Firefox和IE下的弹出窗口
    内存不能为"written"错误&数据保护功能
    1~n's permutation
    pl/sqlcoalesce/nvl
    【TODO】JavaScript Demo
    pl/sqlexecute immediate usage [transferred]
    some coments of struts 1
    pl/sqldecode/case/continue
  • 原文地址:https://www.cnblogs.com/zdqc/p/13476297.html
Copyright © 2020-2023  润新知