tkinter成语语音检索器二

博客提及了成语语音检索器,还列出了相关文件 test2.py 和 wordslib.py ,这些内容与信息技术相关。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

成语语音检索器

# -*- coding: utf-8 -*-
import tkinter
import time
import threading
import tkinter.messagebox
from PIL import ImageTk,Image
import test2
from aip import AipSpeech
import os

APP_ID = '********'
API_KEY = '4Sp******************'
SECRET_KEY = 'YG7L2******************
client = AipSpeech(APP_ID, API_KEY, SECRET_KEY)



#准备好界面
root = tkinter.Tk()
root.title('Xman选择器')
#root.minsize(900, 900)
image2 =Image.open(r'/home/allen/photo.jpg')
background_image = ImageTk.PhotoImage(image2)
w = background_image.width()
h = background_image.height()
root.geometry('%dx%d+0+0' % (w,h))
background_label = tkinter.Label(root, image=background_image)
background_label.place(x=0, y=0, relwidth=1, relheight=1)





def rounds():
    get_words = words.get()
    expl = test2.get_expl(get_words)
    #expl_content = tkinter.Label(root, bg='white', text=expl[0:30]+'\n'+expl[31:80], font=("宋体", 15))
    #expl_content.grid(row=1, sticky='W')
    expl_content = tkinter.Text(root, width=40, height=8, font=("宋体", 15))
    expl_content.place(x=100, y=260)
    expl_content.insert(1.0, expl)
    text = "您输入的成语是" + "。" + get_words + "。" + "。" + "这个成语的意思是" + "。" + expl
    result = client.synthesis(text, 'zh', 1, {
        'sdp': 5, 'vol': 5
    })

    # 识别正确返回语音二进制 错误则返回dict 参照下面错误码
    if not isinstance(result, dict):
        with open('audio.mp3', 'wb') as f:
            f.write(result)

    os.system("/usr/bin/totem /root/audio.mp3")


def get_explain():
#
    t = threading.Thread(target=rounds)
    t.start()

#te = tkinter.Text(height = 30,width =100)
#te.pack()
#tkinter.Text.pack()
#frame = tkinter.Frame(root)
#v1 = tkinter.StringVar()

#frm = tkinter.Frame(root)
#frm_L = tkinter.Frame(frm)
words_prom = tkinter.Label(root, text='请输入成语:', font=("宋体", 15))
words_prom.place(x=100, y=100, width=200, height=50)
#words_prom.grid(row=5, column=3, sticky='W')
words = tkinter.Entry(root, font=("宋体", 20))
words.place(x=310, y=100, width=200, height=50)
#words.grid(row=5, column=4, sticky='E')
#frm_L.pack(side='left')

#frm_R = tkinter.Frame(frm)
expl_prom = tkinter.Label(root, text='成语的意思是:', font=("宋体", 15))
expl_prom.place(x=100, y=200, width=200, height=50)
#expl_prom.grid(row=8, column=3, sticky='W')
#frm_R.pack(side='right')

#btn_start = tkinter.Button(root, text='确定', bg='gold')
btn_start = tkinter.Button(root, text='确定', command=get_explain, bg='gold')
#btn_start.bind("<Return>", get_explain)
btn_start.focus_set()
btn_start.pack()
btn_start.place(x=300, y=550, width=300, height=50)
btn_start.config(font=("Courier", 30))

root.mainloop()

test2.py

# -*- coding: utf-8 -*-

import wordslib




#words = input("请输入成语:")

def get_expl(get_words):
    while True:
        if get_words in wordslib.wordsall.keys():
            explain = wordslib.wordsall[get_words]
            break
        else:
            get_words = input("你输入了一个错误的成语,请重新输入:")

    return explain

wordslib.py

# -*- coding: utf-8 -*-
wordsall = {
"白手空拳":"形容手中一无所有。",
"百般无赖":"采用所有卑鄙的方法。",
"百川赴海":"百:表示多。川:江河。所有江河都流归大海。比喻众望所归或大势所趋。也比喻许多事物由分散而汇集到一处。",
"百川灌河":"河:黄河。所有的河流都流向黄河。比喻人心所向,大势所趋。",
"百川之主":"百川:江河。所有江河最终都流归大海,用以称大海。",
"尺有所短":"比喻事物有其短处,并非在所有的情况下都是合适的。",
"赤贫如洗":"赤贫:穷得一无所有。形容极其贫穷。",
"杼柚其空":"形容生产废弛,贫无所有。",
"杼柚之空":"形容生产废弛,贫无所有。",
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值