zoukankan      html  css  js  c++  java
  • 简单自然语言处理

    官网文档

    代码

    from aip import AipSpeech
    import os
    from aip import AipNlp
    
    """ 你的 APPID AK SK """
    APP_ID = '15842727'
    API_KEY = 'gBsfoHWw4pOh9n3sNhwoB853'
    SECRET_KEY = '4e0WXxlTo5lMgFu45lLnO490SnnpLQLN'
    
    client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)
    nlp_client = AipNlp(APP_ID,API_KEY,SECRET_KEY)
    
    res = nlp_client.simnet('你叫什么名字','你的名字叫什么')
    print('两个字段的相识度',res.get('score'))
    
    # 读取文件
    def get_file_content(filePath):
        os.system(f"ffmpeg -y  -i {filePath}  -acodec pcm_s16le -f s16le -ac 1 -ar 16000 {filePath}.pcm")
        with open(f"{filePath}.pcm", 'rb') as fp:
            return fp.read()
    
    
    # 识别本地文件
    ret = client.asr(get_file_content('mz.wma'), 'pcm', 16000, {
        'dev_pid': 1536,
    })
    
    text = ret.get("result")[0]
    
    #智能问答
    
    def my_nlp(text):
        if nlp_client.simnet(text,"你叫什么名字").get('score') >= 0.58:
            a = '我叫人工智障'
            return a
    
        if nlp_client.simnet(text,"你今年几岁了").get('score') >= 0.75:
            a = '永远18岁'
            return a
        a = "我不知道你在说什么"
        return a
    a = my_nlp(text)
    result = client.synthesis(a, 'zh', 1, {
        'vol': 5,
        'spd': 4,
        'pit': 7,
        'per': 4,
    })
    
    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        with open('audio.mp3', 'wb') as f:
            f.write(result)
    
        os.system('audio.MP3')

    58% :为相似

    80%:极度相似

  • 相关阅读:
    eclipse常用快捷键
    Sql server 问题诊断
    Oracle 表格大小分析
    VM虚拟机增加磁盘空间
    Linux搭建Nexus+Maven私人仓库
    Linux 下安装Git 版本管理工具 使用记录
    Jenkins 环境打建设 Linux
    Oracle 数据库用户表大小分析
    Windgb 其他常用命令
    Windbg 查内存占用
  • 原文地址:https://www.cnblogs.com/wanglan/p/10595830.html
Copyright © 2011-2022 走看看