【python】tkinter界面化+百度API(前面四个功能的整合)—语音系统(五)

 这篇是对前面四个功能的整合,调用了百度API里的语音识别,文本翻译,人脸检测,聊天机器人四个功能。其实就是对设计个GUI界面将前面四个代码整合成一篇,具体的API调用实现这里就不再多说

实现结果看下面这个视频:

【python】tkinter界面化+百度API——语音系统

 直接上完整代码:

(我只是将四个功能直接copy整合,所以里面有好几个方法在各个类里重复出现。)。。。其实就是懒得调试了!!哈哈哈哈哈哈哈

from tkinter import *
from PIL import Image,ImageTk
from aip import  AipSpeech
import pyaudio
from scipy import fftpack
import wave
import numpy as np
import requests
import pyttsx3
import matplotlib.pyplot as plt
import base64
import tkinter.filedialog
import random
import cv2

#主界面设计,创建类,在构造方法中没计界面
class StartPage():
    def __init__(self):
        self.ASR = ASR()
        self.Translate = Translate()
        self.Face_Detection = Face_Detection()
        self.Unit_Robot = Unit_Robot()
        #创建窗口
        self.root = Tk()# Toplevel() # Tk()
        self.root.resizable(width=False, height=False) #设置窗口不可改变大小
        self.root.title('语音系统')  #设置标题
        self. root. geometry('500x800') #设置窗口大小
        # 打开图像,转为tkinter兼容的对象,
        img = Image.open('1.jpg').resize([500,800])
        self.img = ImageTk.PhotoImage(img)
        #创建画布,将图像作为画布背景, 铺满整个窗口
        self.canvas = Canvas(self.root, width=500, height=800) #设置画布的宽、高
        self.canvas.place(x=0, y=0)
        self.canvas.create_image(250,400,image = self.img) #把图像放到画布,默认放置中心点
        self.canvas.create_text(250,100,text = '语音系统',font=('宋体', 40)) #在画布上放置文本(透明背景)
        Button(self.root, width=10, text='语音识别', font=('宋体', 20), fg='white',
               command=lambda :self.jumpweb(1), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x = 175,y = 200)
        Button(self.root, width = 10,text='语音翻译', font=('宋体', 20), fg='white',
               command=lambda :self.jumpweb(2), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x = 175,y = 300)
        Button(self.root, width = 10,text='人脸检测', font=('宋体', 20), fg='white',
               command=lambda :self.jumpweb(3), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x = 175,y = 400)
        Button(self.root, width = 10,text='聊天机器人', font=('宋体', 20), fg='white',
               command=lambda :self.jumpweb(4), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x = 175,y = 500)
        Button(self.root, width=10, text='退    出', font=('宋体', 20), fg='white',
               command=lambda :self.jumpweb(5), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x = 175,y = 600)
        self.root.mainloop(0)

    def jumpweb(self,N):
        if N == 1:
            self.root.destroy()
            self.ASR.AsrPage()
        elif N == 2:
            self.root.destroy()
            self.Translate.TransPage()
        elif N == 3:
            self.root.destroy()
            self.Face_Detection.FacePage()
        elif N == 4:
            self.root.destroy()
            self.Unit_Robot.UnitPage()
        else:
            self.root.destroy()
'''-----------------------------------------------------------------------------------------------------------------------------------------------------------'''
#语音识别界面设计,创建类,在构造方法中没计界面
class ASR():
    def AsrPage(self):
        self.ID = '语音识别的ID'
        self.Key = '语音识别的API_key'
        self.Secret = '语音识别的Secret_key'
        # 用语音类创建对象
        self.client = AipSpeech(self.ID, self.Key, self.Secret)  # 语音识别对象

        # 创建窗口
        self.window = Tk()  # Toplevel() # Tk()
        self.window.resizable(width=False, height=False)
        self.window.title('语音识别')  # 设置标题
        self.window.geometry('500x800')  # 设置窗口大小

        # 打开图像,转为tkinter兼容的对象,
        img = Image.open('2.jpg').resize([500, 800])
        self.img = ImageTk.PhotoImage(img)
        # 创建画布,将图像作为画布背景, 铺满整个窗口
        self.canvas = Canvas(self.window, width=500, height=800)  # 设置画布的宽、高
        self.canvas.place(x=0, y=0)
        self.canvas.create_image(250, 400, image=self.img)  # 把图像放到画布,默认放置中心点
        self.canvas.create_text(250, 100, text='语音识别', font=('宋体', 40))

        # 创建标题标签
        # Label(self.window, bg='royalblue', text='语音识别', font=('宋体', 40), fg='white').pack(pady=90)  # 上下间隔100
        # 创建文本框
        self.content = Text(self.window, width=22, height=5, font=('宋体', 20))
        self.content.place(x=100, y=200)
        # 创建按钮
        Button(self.window, width=10, text='语音转文字', font=('宋体', 20), fg='white',
               command=lambda: self.StoT(), bg='dodgerblue', activebackground='black',
               activeforeground='white').place(x=100, y=600)  # activebackground 设置按键按下有变化 activebforeground设置前景色
        # Button(self.window, width = 5,text='识别', font=('宋体', 20), fg='white',
        #        command=self.jumpweb2, bg='dodgerblue', activebackground='black',
        #        activeforeground='white').place(x = 200, y =600)
        Button(self.window, width=10, text='文字转语音', font=('宋体', 20), fg='white',
               command=lambda:
  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张顺财

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值