[Last article] As you can see (https://qiita.com/tkmktdm/items/6f8e363858f4061d8cfd), last time, when saving automatically, it was only saved in the same file. However, as a result of writing an html file and loading the audio file with javascript, do I have to reopen it or load another file? I wanted to see it. (I don't know the details lol)
Prepare global variables in the main program file created last time and count the number sent.
Use the Inspect tool to find the location in the Name field [Combo Box] under Save As. Then, the global variable prepared in main is put in there and given a different name.
aitalk.py
import wave
import winsound as ws
import tkinter
import sys
import tkinter.messagebox as tkm
import time
from voice2 import talkVOICEROID2
from voiceroid2_1 import talkVOICEROID2_1
from voiceroid2_2 import talkVOICEROID2_2
from voiceroid2_3 import talkVOICEROID2_3
from voiceroid2_4 import talkVOICEROID2_4
import time
#Define it for global use(For counting times)
setnumber = 0
root=tkinter.Tk()
root.geometry("1920x1080")
root.title(u"aoi talk")
kotonoha=tkinter.PhotoImage(file="C:/Users/takumi/Desktop/voice/01.png ")
canvas=tkinter.Canvas(bg="white",width=475,height=750)
canvas.place(x=1300,y=250)
canvas.create_image(0,0, image=kotonoha, anchor=tkinter.NW)
def addlist(text):
mysay="you: "+ text
print(mysay)
listbox.insert(tkinter.END,mysay)
chat = "Aoi: " + talk(text)
Entry1.delete(0, tkinter.END)
chatCut(chat)
def chatCut(chat):
aoi=chat
addRep(aoi)
def addRep(aoi):
listbox.insert(tkinter.END, aoi)
global setnumber
setnumber+=1
#Voice processing
voiceroid=aoi[5:]
voiceroid=voiceroid+"Tsu"
word=len(voiceroid)
destime=round(word/7+0.1,1)
#destime=round(word/7+1.1,1)
#If you can't speak on the desktop, add the following comment out
talkVOICEROID2(voiceroid)
time.sleep(destime)
print(destime)
#-----------zzz
talkVOICEROID2_1(voiceroid)
time.sleep(0.3)
talkVOICEROID2_2(voiceroid,setnumber)
time.sleep(0.2)
talkVOICEROID2_3(voiceroid)
time.sleep(0.2)
talkVOICEROID2_4(voiceroid)
def talk(say):
if say == 'end':
return ('see you')
else:
return (say)
static=tkinter.Label(text=u"Talk to Aoi-chan!")
static.pack()
Entry1=tkinter.Entry(width=50)
Entry1.insert(tkinter.END,u"Hello")
Entry1.pack()
button=tkinter.Button(text=u"Send", width=50,command=lambda: addlist(Entry1.get()))
button.pack()
listbox=tkinter.Listbox(width=55,height=15)
listbox.pack()
root.mainloop()
** Change only voiceroid2_2.py file **
voiceroid2_2.py
#Second time
# -*- coding: utf-8 -*-
import pywinauto
def search_child_byclassname_2(class_name, uiaElementInfo, target_all = False):
target = []
#Search all child elements
for childElement in uiaElementInfo.children():
#ClassName match confirmation
if childElement.class_name == class_name:
if target_all == False:
return childElement
else:
target.append(childElement)
if target_all == False:
#False if not
return False
else:
return target
def search_child_byname_2(name, uiaElementInfo):
#Search all child elements
for childElement in uiaElementInfo.children():
#Name match confirmation
if childElement.name == name:
return childElement
#False if not
return False
def talkVOICEROID2_2(speakPhrase,num):
setnumber=str(num) + ".wav"
print(setnumber)
#Desktop elements
parentUIAElement = pywinauto.uia_element_info.UIAElementInfo()
#Search for voiceroid
voiceroid2 = search_child_byname_2("VOICEROID2",parentUIAElement)
# *If is attached
if voiceroid2 == False:
voiceroid2 = search_child_byname_2("VOICEROID2*",parentUIAElement)
#Change from here
#Save as Get ElementInfo of element
saveEle = search_child_byclassname_2("#32770",voiceroid2)
#Name editing
win = search_child_byclassname_2("DUIViewWndClassName",saveEle)
winwin = search_child_byclassname_2("AppControlHost",win)
filewin = search_child_byclassname_2("Edit",winwin)
textBoxEditControl = pywinauto.controls.uia_controls.EditWrapper(filewin)
textBoxEditControl.set_edit_text(setnumber)
playsaveEle = search_child_byclassname_2("Button",saveEle,target_all = False)
#Get button control
playButtonControl = pywinauto.controls.uia_controls.ButtonWrapper(playsaveEle)
#Press the play button
playButtonControl.click()
This time too, I was able to save it to another file and succeeded! !! Please note that the structure in Windows may be different depending on the person! (;^ω^)
Recommended Posts