I wanted to create some content using VOICEROID, but I can't hear the audio on a computer that doesn't have VOICEROID software! !! ** **
Then, I thought "Let's find the API and do something about it!", But I searched for the API, but I could not find it at all, so I passed the entered text through VOICEROID, saved the audio file, and made something to call it. It was.
** Reference article ** Try moving VOICEROID2 (Kizuma Akari) from the program How do I use the Inspect tool to investigate the UI? [Windows 8 / Windows 8.1 Store App Development]
** Used etc. ** python3 {tkinter, wave, pywinauto}
Use python3's tkinter to display input boxes, submit buttons, and character images. When you press the send button, the text will be sent to the VOICEROID software, so save it as voice. (Using pywinauto)
If you look at the program with reference to what is written in Reference article, you can see that getting the handle of the window is the key to this time. .. To see how it works, we use a tool called Inspect.exe that allows you to see how the UI works.
"-" Indicates the lower layer
desktop
- "VOICEROID2"window
-- ""custom
--- ""button
---- "Voice storage"text
"-" Indicates the lower layer
desktop
- "VOICEROID2"window
-- "save as"dialog
--- "Save(S)"button
"-" Indicates the lower layer
desktop
- "VOICEROID2"window
-- "save as"dialog
--- "save as"dialog
----| "Yes(Y)"button
----| "No(N)"button
"-" Indicates the lower layer
desktop
- "VOICEROID2"window
-- "Voice storage"window
--- "information"dialog
---- "OK"button
** Cocco ** is the most annoying, and multiple similar names appear, which makes the hierarchy strange. It hurts my head, so let's play a song or drink coffee.
from voice2 import talkVOICEROID2 uses Reference article as it is. Start VOICEROID2 in advance and then execute voiceroidtalk.py. There is a confirmation window when moving from VOICEROID2 voice save to "Save As", but this time it is set to "Omit from next time"
voiceroidtalk.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
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)
#if 0<=int(text):
# aoivoice=int(text)
Entry1.delete(0, tkinter.END)
chatCut(chat)
#addRep(aoi)
def chatCut(chat):
aoi=chat
addRep(aoi)
def addRep(aoi):
listbox.insert(tkinter.END, aoi)
#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)
#-----------zzz
#Change the time delay processing according to the specifications
talkVOICEROID2_1(voiceroid)
time.sleep(0.3)
talkVOICEROID2_2(voiceroid)
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()
If you have the power to put it together more easily ...
voiceroid2_1.py
# -*- coding: utf-8 -*-
import pywinauto
def search_child_byclassname_1(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_1(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_1(speakPhrase):
#Desktop elements
parentUIAElement = pywinauto.uia_element_info.UIAElementInfo()
#Search for voiceroid
voiceroid2 = search_child_byname_1("VOICEROID2",parentUIAElement)
# *If is attached
if voiceroid2 == False:
voiceroid2 = search_child_byname_1("VOICEROID2*",parentUIAElement)
#Change from here
#Get ElementInfo of text element
TextEditViewEle = search_child_byclassname_1("TextEditView",voiceroid2)
textBoxEle = search_child_byclassname_1("TextBox",TextEditViewEle)
#Get control
textBoxEditControl = pywinauto.controls.uia_controls.EditWrapper(textBoxEle)
#Text registration
textBoxEditControl.set_edit_text(speakPhrase)
#Get button
buttonsEle = search_child_byclassname_1("Button",TextEditViewEle,target_all = True)
#Find the play button
playButtonEle = ""
for buttonEle in buttonsEle:
#Search for text blocks
textBlockEle = search_child_byclassname_1("TextBlock",buttonEle)
if textBlockEle.name == "Voice storage":
playButtonEle = buttonEle
break
#Get button control
playButtonControl = pywinauto.controls.uia_controls.ButtonWrapper(playButtonEle)
#Press the play button
playButtonControl.click()
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):
#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)
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()
voiceroid2_3.py
#Third time
# -*- coding: utf-8 -*-
import pywinauto
def search_child_byclassname_3(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_3(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_3(speakPhrase):
#Desktop elements
parentUIAElement = pywinauto.uia_element_info.UIAElementInfo()
#Search for voiceroid
voiceroid2 = search_child_byname_3("VOICEROID2",parentUIAElement)
# *If is attached
if voiceroid2 == False:
voiceroid2 = search_child_byname_3("VOICEROID2*",parentUIAElement)
#Change from here
#Get the ElementInfo of the save element with the first name
saveEle = search_child_byclassname_3("#32770",voiceroid2)
#Save as a second name(Yes or no)Get ElementInfo of element
resaveEle = search_child_byclassname_3("#32770",saveEle)
#Store inside the handle inside the second(Get YES button)
yessEle = search_child_byclassname_3("Button",resaveEle,target_all = True)
#Find the yes button
playyesEle = ""
for yesEle in yessEle:
#The current handle in the first argument, the previous save handle in the second argument
#Look for name yes in where you are
a=search_child_byclassname_3("#32770",saveEle)
if yesEle.name=="Yes(Y)":
playyesEle=yesEle
break
#Get button control
playButtonControl = pywinauto.controls.uia_controls.ButtonWrapper(playyesEle)
#Press the play button
playButtonControl.click()
voiceroid2_4.py
#4th
# -*- coding: utf-8 -*-
import pywinauto
def search_child_byclassname_4(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_4(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_4(speakPhrase):
#Desktop elements
parentUIAElement = pywinauto.uia_element_info.UIAElementInfo()
#Search for voiceroid
voiceroid2 = search_child_byname_4("VOICEROID2",parentUIAElement)
# *If is attached
if voiceroid2 == False:
voiceroid2 = search_child_byname_4("VOICEROID2*",parentUIAElement)
#Change from here
#Audio save window(Save confirmation)Get ElementInfo of element
wavEle = search_child_byclassname_4("Window",voiceroid2)
#Get ElementInfo for information dialog element
infoEle = search_child_byclassname_4("#32770",wavEle)
#YES button acquisition
yessEle = search_child_byclassname_4("Button",infoEle,target_all = True)
#Find the yes button
playyesEle = ""
for yesEle in yessEle:
#Search for text blocks
w=search_child_byclassname_4("#32770",wavEle)
if yesEle.name=="OK":
playyesEle=yesEle
break
#Get button control
playButtonControl = pywinauto.controls.uia_controls.ButtonWrapper(playyesEle)
#Press the play button
playButtonControl.click()
I was able to take it out safely! !! Aoi Chan Kawaii Yatter (Fatigue) Well, at this stage, only people who have VOICEROID2 can do it, but I would like to be able to do this on a web page.
Recommended Posts