Exemple #1
0
def upload(request):
    # print(request.POST)
    file_name = os.path.join('robot_app', 'static', 'audio_file',
                             request.POST['name'])
    file = request.FILES['file']

    with open(file_name, 'wb') as f:
        f.write(file.read())

    text = audio2text(file_name)
    index = get_high_sim(text)
    if index is not None:
        answer = read_answer(index)
    else:
        answer = get_roboot_answer(text)

    hecheng_name = os.path.join('robot_app', 'static', 'audio_file',
                                'hecheng' + request.POST['name'])

    if text2audio(answer, hecheng_name):
        print('合成成功!')
        res_name = hecheng_name.strip('robot_app//')
    else:
        print('合成失败!')
        res_name = ''

    res_str = {'play_tpe': 'talk', 'res_name': res_name, 'content': text}

    return HttpResponse(json.dumps(res_str), content_type='application/json')
Exemple #2
0
def upload(request):
    # print(request.POST)
    file_name = os.path.join('robot_app', 'static', 'audio_file', request.POST['name'])
    file = request.FILES['file']
    print(request)
    with open(file_name, 'wb') as f:
        f.write(file.read())

    text = audio2text(file_name)
    print('识别结果', text)
    index = get_high_sim(text)
    if index is not None:
        answer = read_answer(index)
        if index == 3:
            os.popen('notepad')
        elif index == 4:
            os.popen(qq_exe)
            # os.popen(r'D:\日常应用\QQ\Bin\QQScLauncher.exe')
        elif index==5:
            os.popen(kill_qq)
        elif index==6:
            os.popen(music_exe)
            # os.popen(r'D:\音乐\CloudMusic\cloudmusic.exe')
        elif index==7:
            os.popen(kill_music)
        elif index == 8:
            keyword = text[text.rfind('音乐') + 2:]
            print('播放音乐keyword:',keyword)
            song_name = play_song(keyword)
            print('songname:',song_name)
            if song_name:
                print('好的', song_name)
                # return '好的', song_name
            else:
                mysearch_kw(keyword)
                print('好不到歌曲,百度搜索中···')
                # return search_kw('杨宗纬 - 越过山丘'),
        elif 9 <= index <= 13:
            play_function(index)
        elif index==14:
            # 等待一秒调整截图屏幕,转到要截图的界面
            time.sleep(1)
            capture()
        elif index==15:
            keyword = text[text.rfind('搜索') + 2:]
            # print('搜索keyword:',keyword)
            # shurl= r'https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd={}'.format(keyword)
            # print('搜索的url:',shurl)
            # shcmd='explorer "'+shurl+'"'
            # print('搜索cmd:',shcmd)
            # os.popen(shcmd)
            mysearch_kw(keyword)

    else:
        answer = get_myroboot_answer(text)

    hecheng_name = os.path.join('robot_app', 'static', 'audio_file', 'hecheng' + request.POST['name'])

    if text2audio(answer.replace('<br>',' '), hecheng_name):
        print('合成成功!')
        res_name = hecheng_name.strip('robot_app//')
    else:
        print('合成失败!')
        res_name = ''

    res_str = {
        'play_tpe': 'talk',
        'res_name': res_name,
        'content': answer,
        'history':text
    }

    return HttpResponse(json.dumps(res_str), content_type='application/json')
Exemple #3
0
def upload(request):
    # print(request.POST)
    file_name = os.path.join('robot_app', 'static', 'audio_file', request.POST['name'])
    file = request.FILES['file']

    with open(file_name, 'wb') as f:
        f.write(file.read())
    text = audio2text(file_name)
    if text[0:2] == '搜索' or text[0:2] == '发送' or text[0:2] == '播放':
        index = get_high_sim(text[0:2])
    else:
        index = get_high_sim(text)
    if index is not None:
        answer = read_answer(index)
        if index == 4:
            os.popen('notepad')
        if index == 3:
            os.popen('G:\QQ\Bin\QQScLauncher.exe')
            time.sleep(5)
            win32api.keybd_event(13, 0, 0, 0)  # enter键位码是86
            win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)
        if index == 5:
            driver = webdriver.Chrome()  # 利用浏览器
            driver.get("http://www.baidu.com")  # 打开get到的网址
            time.sleep(3)  # t停顿3秒,即3秒内一直在这个界面
            # print("网站的名称:",driver.title)  # 获取网站名称并输出     #打开keyword.txt文件,并一行行读取数据:keyword.txt中可以存放任意关键字,比如:selenium python 赵丽颖(ps:一个关键字占一行)
            driver.find_element('id', 'kw').send_keys(text[2:])  # 通过输入框的id为kw,定位到输入框,输入”selenium”
            driver.find_element('id', 'su').click()  # 通过搜索按钮的id为su定位到搜索按钮,点击按钮
            # time.sleep(5)  # 停顿5秒
        if index == 6:
            picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
            directory_time = time.strftime("%Y-%m-%d", time.localtime(time.time()))
            print(picture_time)
            print(directory_time)
            # 打印文件目录
            print(os.getcwd())
            # 获取到当前文件的目录,并检查是否有 directory_time 文件夹,如果不存在则自动新建 directory_time 文件
            try:
                File_Path = os.getcwd() + '\\' + directory_time + '\\'
                if not os.path.exists(File_Path):
                    os.makedirs(File_Path)
                    print("目录新建成功:%s" % File_Path)
                else:
                    print("目录已存在!!!")
            except BaseException as msg:
                print("新建目录失败:%s" % msg)
            driver = webdriver.Chrome()
            driver.get("https://baidu.com/")
            try:
                url = driver.save_screenshot('.\\' + directory_time + '\\' + picture_time + '.png')
                print("%s :截图成功!!!" % url)
            except BaseException as pic_msg:
                print("截图失败:%s" % pic_msg)
            time.sleep(2)
            driver.quit()
        if index == 7:
            os.popen('G:\CloudMusic\cloudmusic.exe')
            time.sleep(8)
            start()
        if index == 8:
            x=text.index('给')
            int(x)
            to_who=text[x+1:]
            msg=text[2:x]
            qq(to_who)
            send_qq(to_who,msg)
        if index == 9:
            stop()
        if index == 10:
            last()
        if index == 11:
            next()
        if index == 12:
            turn_up()
        if index == 13:
            turn_down()
        if index == 14:
            love()
        if index == 15:
            show_words()
        if index == 16:
            shoutsown_words()
        if index == 17:
            os.system(r'taskkill /f /t /im cloudmusic.exe')
        if index == 18:
            start()
        if index == 19:
            music=text[2:]
            find_music()
            time.sleep(1)
            play_music(music)
    else:
        answer = get_roboot_answer(text)
    con[text]=answer
    hecheng_name = os.path.join('robot_app', 'static', 'audio_file', 'hecheng' + request.POST['name'])

    if text2audio(answer, hecheng_name):
        print('合成成功!')
        res_name = hecheng_name.strip('robot_app//')
    else:
        print('合成失败!')
        res_name = ''

    res_str = {
        'play_tpe': 'talk',
        'res_name': res_name,
        'content': answer
    }

    return HttpResponse(json.dumps(res_str), content_type='application/json')
Exemple #4
0
    index.save('Lsi_matrix.index')
    return index


def get_high_sim(doc):

    doc_test_list = list(jieba.cut(doc))
    # 将需要寻找相似度的分词列表 做成 语料库 doc_test_vec
    doc_test_vec = dictionary.doc2bow(doc_test_list)
    sim = index[lsi[doc_test_vec]]

    # 对下标和相似度结果进行一个排序,拿出相似度最高的结果
    cc = sorted(enumerate(sim), key=lambda item: -item[1])
    print(cc)

    high_score = cc[0]
    text = raw_docs[high_score[0]]

    print(doc, '-------', text)
    print('相似度:', high_score[1])
    if high_score[1] > sim_degree:
        return cc[0][0]


index = get_index_matrix()

if __name__ == '__main__':
    doc = '你今年多大了'
    index = get_high_sim(doc)
    print(read_answer(index))