最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

傻瓜讀書軟件完成版TK代碼(功能滿足,但不完美)

2020-03-30 17:44 作者:一心想當網(wǎng)紅的李老師  | 我要投稿

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

"""

Created on Sun Mar 29 11:01:21 2020


@author: liyan

"""

import importlib,sys

importlib.reload(sys)


import tkinter

from tkinter.filedialog import askopenfilename

from docx import Document

from docx.shared import Inches

import pyttsx3

from tkinter import *

from tkinter import ttk

import os

import pyaudio

import time

import threading

import wave



class Recorder():

? ? def __init__(self, chunk=1024, channels=1, rate=64000):

? ? ? ? self.CHUNK = chunk

? ? ? ? self.FORMAT = pyaudio.paInt16

? ? ? ? self.CHANNELS = channels

? ? ? ? self.RATE = rate

? ? ? ? self._running = True

? ? ? ? self._frames = []

? ? def start(self):

? ? ? ? threading._start_new_thread(self.__recording, ())

? ? def __recording(self):

? ? ? ? self._running = True

? ? ? ? self._frames = []

? ? ? ? p = pyaudio.PyAudio()

? ? ? ? stream = p.open(format=self.FORMAT,

? ? ? ? ? ? ? ? ? ? ? ? channels=self.CHANNELS,

? ? ? ? ? ? ? ? ? ? ? ? rate=self.RATE,

? ? ? ? ? ? ? ? ? ? ? ? input=True,

? ? ? ? ? ? ? ? ? ? ? ? frames_per_buffer=self.CHUNK)

? ? ? ? while(self._running):

? ? ? ? ? ? data = stream.read(self.CHUNK)

? ? ? ? ? ? self._frames.append(data)

?

? ? ? ? stream.stop_stream()

? ? ? ? stream.close()

? ? ? ? p.terminate()

?

? ? def stop(self):

? ? ? ? self._running = False

?

? ? def save(self, filename):

? ? ? ??

? ? ? ? p = pyaudio.PyAudio()

? ? ? ? if not filename.endswith(".wav"):

? ? ? ? ? ? filename = filename + ".wav"

? ? ? ? wf = wave.open(filename, 'wb')

? ? ? ? wf.setnchannels(self.CHANNELS)

? ? ? ? wf.setsampwidth(p.get_sample_size(self.FORMAT))

? ? ? ? wf.setframerate(self.RATE)

? ? ? ? wf.writeframes(b''.join(self._frames))

? ? ? ? wf.close()

? ? ? ? print("Saved")



l=[]

def openfile():

? ? global file_path,l

? ? file_path=askopenfilename() ?

? ??

? ? if os.path.splitext(str(file_path))[1]=='.txt': ?###對于TXT文件的處理

? ? ? ? f=open(file_path,encoding='utf-8')

? ? ? ? fread=f.read()

? ? ? ? f=str(fread)

? ? ? ? text.insert(END,f) ??

? ? elif os.path.splitext(str(file_path))[1]=='.docx': ###對于WORD文件處理

? ? ? ? f=Document(file_path)

? ? ? ? for para in f.paragraphs:

? ? ? ? ? ? l.append(para.text)

? ? ? ? text.insert(END,str(l))


def cleartext():

? ? text.delete('1.0','end')



def readbook():

? ? global l

? ? l=text.get('0.0', 'end')

? ? engine=pyttsx3.init()

? ? engine.say(str(l))

? ? engine.runAndWait()

? ??

? ??

? ??

def readtext():

? ? global l,rec

? ? l=text.get('0.0', 'end')

? ? strtime=time.strftime("%Y%m%d%H%M%S", time.localtime())

? ? name=strtime+".wav"

? ? rec = Recorder()

? ? begin = time.time()

? ? rec.start()

? ? print("Start recording")

? ? engine=pyttsx3.init()

? ? engine.say(str(l))

? ? engine.runAndWait()

? ? print("Stop recording")

? ? rec.stop()

? ? fina = time.time()

? ? rec.save(name)


if __name__=='__main__':

? ? root=Tk()

? ? root.title('讀書軟件')

? ? root.geometry("720x480")

? ? root.configure(bg="white")

? ? text=tkinter.Text(root,bg="yellow")

? ? text.grid(row=2,columnspan=4,padx=20,pady=20)?

? ? Button1=tkinter.Button(root, text ="選擇文件", command = openfile)

? ? Button1.grid(row=0,column=0,padx=20,pady=20)

? ? Button2=tkinter.Button(root, text ="清空內(nèi)容", command = cleartext)

? ? Button2.grid(row=0,column=1,padx=20,pady=20)

? ? Button3=tkinter.Button(root, text ="語音讀書", command = readbook)

? ? Button3.grid(row=0,column=2,padx=20,pady=20)

? ? Button4=tkinter.Button(root, text ="錄音輸出", command = readtext)

? ? Button4.grid(row=0,column=3,padx=20,pady=20)

? ? root.mainloop()


傻瓜讀書軟件完成版TK代碼(功能滿足,但不完美)的評論 (共 條)

分享到微博請遵守國家法律
弋阳县| 崇阳县| 阳曲县| 酒泉市| 赫章县| 铅山县| 杭锦后旗| 洛阳市| 剑阁县| 洪湖市| 华蓥市| 华池县| 剑河县| 广元市| 乌拉特前旗| 随州市| 嵊州市| 静海县| 德州市| 正镶白旗| 峨眉山市| 诸城市| 砚山县| 邵东县| 额尔古纳市| 婺源县| 贵阳市| 镇沅| 舞钢市| 通城县| 封开县| 台南县| 南通市| 治多县| 民勤县| 林西县| 远安县| 枝江市| 淮北市| 宁化县| 社会|