I tried to read and save automatically with VOICEROID2 2

Introduction

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

Specifically

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.

Main screen

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

Processing part

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

Finally

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

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 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 use lightGBM, xgboost with Boruta
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 playing with PartiQL and MongoDB connected
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