I tried to automatically read and save with VOICEROID2

Introduction

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}

Concrete structure

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)

Let's see the operation of VOICEROID2

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.

1. Watch the flow of saving voice

"-" Indicates the lower layer

desktop
- "VOICEROID2"window
-- ""custom
--- ""button
---- "Voice storage"text

2. Watch the flow of saving voice

"-" Indicates the lower layer

desktop
- "VOICEROID2"window
-- "save as"dialog
--- "Save(S)"button

3, watch the flow of saving voice

"-" Indicates the lower layer

desktop
- "VOICEROID2"window
-- "save as"dialog
--- "save as"dialog
----| "Yes(Y)"button
----| "No(N)"button

4, watch the flow of saving voice

"-" Indicates the lower layer

desktop
- "VOICEROID2"window
-- "Voice storage"window
--- "information"dialog
---- "OK"button

Take out the corresponding one and write it in the code

** 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.

Before the program code (supplement)

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"

Main screen

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()

Processing part

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()

Finally

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.

Security? ?? Oh, it was a good guy ...

Recommended Posts

I tried to read and save automatically with VOICEROID2 2
I tried to automatically read and save with VOICEROID2
I tried to save the data with discord
I tried to implement and learn DCGAN with PyTorch
I tried to automatically generate a password with Python3
I tried to implement Grad-CAM with keras and tensorflow
I tried to predict and submit Titanic survivors with Kaggle
I tried to automatically create a report with Markov chain
I tried to make GUI tic-tac-toe with Python and Tkinter
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to implement Autoencoder with TensorFlow
I tried to visualize AutoEncoder with TensorFlow
I tried to visualize bookmarks flying to Slack with Doc2Vec and PCA
A memorandum when I tried to get it automatically with selenium
I tried to get started with Hy
I tried to make a periodical process with Selenium and Python
I tried to implement CVAE with PyTorch
I tried to create Bulls and Cows with a shell program
I tried to easily detect facial landmarks with python and dlib
I tried to solve TSP with QAOA
I tried to automatically collect images of Kanna Hashimoto with Python! !!
I tried to log in to twitter automatically with selenium (RPA, scraping)
I tried to express sadness and joy with the stable marriage problem.
Get tweets with Google Cloud Function and automatically save images to Google Photos
I tried to convert datetime <-> string with tzinfo using strftime () and strptime ()
I tried to automatically extract the movements of PES players with software
I tried to learn the angle from sin and cos with chainer
[Outlook] I tried to automatically create a daily report email with Python
[Markov chain] I tried to read quotes and negative emotions into Python.
I tried to control the network bandwidth and delay with the tc command
I tried to predict next year with AI
I tried to detect Mario with pytorch + yolov3
I tried to implement reading Dataset with PyTorch
I tried to learn logical operations with TF Learn
I tried to move GAN (mnist) with keras
I implemented DCGAN and tried to generate apples
I tried to detect motion quickly with OpenCV
I tried to integrate with Keras in TFv1.1
I tried Jacobian and partial differential with python
I tried to get CloudWatch data with Python
I tried function synthesis and curry with python
I tried to output LLVM IR with Python
I tried to detect an object with M2Det!
I tried to automate sushi making with python
I tried to predict Titanic survival with PyCaret
I tried to operate Linux with Discord Bot
I tried to study DP with Fibonacci sequence
I tried to start Jupyter with Amazon lightsail
I tried to judge Tsundere with Naive Bayes
[Introduction to PID] I tried to control and play ♬
I tried to debug.
I tried to paste
I tried to make a periodical process with CentOS7, Selenium, Python and Chrome
I tried to automate internal operations with Docker, Python and Twitter API + bonus
[ES Lab] I tried to develop a WEB application with Python and Flask ②
[Introduction to AWS] I tried porting the conversation app and playing with text2speech @ AWS ♪
I tried to make a simple image recognition API with Fast API and Tensorflow
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to learn the sin function with chainer
I tried to move machine learning (ObjectDetection) with TouchDesigner
I tried to create a table only with Django