zoukankan      html  css  js  c++  java
  • 百度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.究极版

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

  • 相关阅读:
    celery完成简单的定时任务
    看直播软件源码,如何实现直播系统业务以及技术注意点分析
    直播后台开发,php直播源码这样选择才不会出错
    直播平台源代码的基础功能和首屏优化,小白必看点
    开发短视频软件,短视频源码具有无限的开发潜力
    直播带货源码的安全稳定性到底有多重要?
    搭建直播平台,选对视频直播系统源码有多重要?
    提升短视频应用体验,短视频源码要做哪些完善?
    全世界都在用的编程语言,php直播源码你还不知道就out了
    直播带货系统源码如何举稳直播带货风潮下的大旗
  • 原文地址:https://www.cnblogs.com/zdqc/p/13476297.html
Copyright © 2011-2022 走看看