国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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代碼(功能滿足,但不完美)的評論 (共 條)

分享到微博請遵守國家法律
南华县| 咸阳市| 舒兰市| 威信县| 台北市| 富顺县| 巨鹿县| 郯城县| 南华县| 隆德县| 勐海县| 日土县| 青铜峡市| 安阳县| 独山县| 乐安县| 镇赉县| 城口县| 新乡市| 长沙市| 新河县| 堆龙德庆县| 洛浦县| 大兴区| 铁岭县| 施甸县| 长乐市| 巫山县| 双城市| 南丹县| 濮阳市| 高唐县| 米泉市| 新竹县| 应城市| 赞皇县| 东阿县| 石阡县| 瓦房店市| 靖远县| 榆树市|