カテゴリー
PC ゆっくりMovieMaker

PowerShellでゆっくりムービーメーカー3のセリフ・表情を一発入力

Book1PowerShellでゆっくりムービーメーカー3のセリフ・表情を一発入力するスクリプトを作ってみた。

チャンネル登録をお願いします。
https://www.youtube.com/channel/UCplPgEYD8YLU_s4Lez4INJw?sub_confirmation=1

PowerShellスクリプト yukkuri.ps1

#Import-Module C:\Temp\UIAutomation.dll
Import-Module ..\UIAutomation.dll


$script:current_char = 0
$UIAChildrenScope = [System.Windows.Automation.TreeScope]::Children
$UIATrue          = [System.Windows.Automation.Condition]::TrueCondition



#タイムラインとアイテム編集は表示オンになってる前提
$mainWindow  = Get-UiaWindow -Class 'Window' -Name 'ゆっくりMovieMaker v3.4.8.1 (x0.47)' 
$win_timeline = $mainWindow.FindAll($UIAChildrenScope, $UIATrue) | Where-Object {$_.Current.Name -like "タイムライン*"}
$win_itemedit = $mainWindow.FindAll($UIAChildrenScope, $UIATrue) | Where-Object {$_.Current.Name -like "アイテム編集"}

#キャラを変えるためのCTRL+上下矢印キー押下の関数
function char_up {
 	$win_timeline.Keyboard.KeyDown([WindowsInput.Native.VirtualKeyCode]::CONTROL) | Out-Null; 
	$win_timeline.Keyboard.KeyPress([WindowsInput.Native.VirtualKeyCode]::UP) | Out-Null;   
	$win_timeline.Keyboard.KeyUp([WindowsInput.Native.VirtualKeyCode]::CONTROL) | Out-Null; 
}

function char_down {
 	$win_timeline.Keyboard.KeyDown([WindowsInput.Native.VirtualKeyCode]::CONTROL) | Out-Null; 
	$win_timeline.Keyboard.KeyPress([WindowsInput.Native.VirtualKeyCode]::DOWN) | Out-Null;   
	$win_timeline.Keyboard.KeyUp([WindowsInput.Native.VirtualKeyCode]::CONTROL) | Out-Null; 
}

#タイムラインを進めるスペースキー押下の関数
function ywait($x) {
	$win_timeline.Keyboard.KeyPress([WindowsInput.Native.VirtualKeyCode]::SPACE) | Out-Null;
	Start-Sleep -m $x
	$win_timeline.Keyboard.KeyPress([WindowsInput.Native.VirtualKeyCode]::SPACE) | Out-Null;
}

# セリフにaを入れて消す。
# これをやらないとアイテム編集でキャラクターの設定が出来ない
char_up;char_up;char_up;char_up
$window = $win_timeline | Get-UiaEdit -AutomationId 'SerifuTB' -Class 'TextBox'
$window.Keyboard.TypeText("a")
$win_timeline | Get-UiaButton -Class 'Button' -Name '追加' | Invoke-UiaTabItemClick | Out-Null  | Invoke-UiaTabItemClick | Out-Null
$win_timeline.Keyboard.KeyPress([WindowsInput.Native.VirtualKeyCode]::DELETE) | Out-Null;   

#表情を変えるために処理
$char_parts = $win_itemedit|Get-UiaCustom -AutomationId 'this' -Class 'ItemEditor' | `
Get-UiaPane -Class 'ScrollViewer' | `
Get-UiaGroup -AutomationId 'FaceSetEx' -Class 'Expander' -Name 'キャラ素材 / パーツ'  | `
Get-UiaCustom -AutomationId 'this' -Class 'CheckTextboxSlider' | `
Get-UiaEdit -AutomationId 'DetTextbox' -Class 'TextBox'
function yparts($p0,$p1,$p2,$p3,$p4,$p5,$p6) {
               #顔 眉 目 口 体 他 後
               $char_parts[0].Value = $p0
               $char_parts[1].Value = $p1
               $char_parts[2].Value = $p2
               $char_parts[3].Value = $p3
               $char_parts[4].Value = $p4
               $char_parts[5].Value = $p5
               $char_parts[6].Value = $p6
}

#キャラのアクションの処理
$char_actions = $win_itemedit|Get-UiaCustom -AutomationId 'this' -Class 'ItemEditor' | `
Get-UiaPane -Class 'ScrollViewer' | `
Get-UiaGroup -AutomationId 'FaceSetEx2' -Class 'Expander' -Name 'キャラ素材 / アクション'  | `
Get-UiaCustom -AutomationId 'this' -Class 'CheckTextboxSlider' | `
Get-UiaEdit -AutomationId 'DetTextbox' -Class 'TextBox'
function yactions($a0,$a1,$a2,$a3,$a4) {
               #顔 眉 目 口 体 他 後
               $char_actions[0].Value = $a0
               $char_actions[1].Value = $a1
               $char_actions[2].Value = $a2
               $char_actions[3].Value = $a3
               $char_actions[4].Value = $a4

}
function change_char($x) {
		"current_char:  $script:current_char   -> $x"
	if ( $x -ne $script:current_char ) {
		
		if ($x -gt $script:current_char) {
			"cnange d"
			for ($i=0; $i -lt $x-$script:current_char; $i++){
				char_down
				"d"
			}
		} else {
			"cnange u"
			for ($i=0; $i -lt $script:current_char-$x; $i++){
				char_up
				"u"
			}
		}
		$script:current_char=$x
	
	
	}

}

#セリフ入力の関数
function yspeak($c,$p0,$p1,$p2,$p3,$p4,$p5,$p6,$a0,$a1,$a2,$a3,$a4,$x) {
	change_char($c)
	$window = $win_timeline | Get-UiaEdit -AutomationId 'SerifuTB' -Class 'TextBox'
	$window.Keyboard.TypeText($x)
	Start-Sleep -m 300

	$win_timeline | Get-UiaButton -Class 'Button' -Name '追加' | Invoke-UiaTabItemClick | Out-Null  | Invoke-UiaTabItemClick | Out-Null

	Start-Sleep -m 500
	yparts $p0 $p1 $p2 $p3 $p4 $p5 $p6
	yactions $a0 $a1 $a2 $a3 $a4
	ywait(100)
	Start-Sleep -m 300
}

######  ここからセリフ ########
#yspeak キャラ  顔 眉 目 口 体 他 後 高 速 間 ク 震 "セリフ"


yspeak 0 3 0 0 0 0 0 0 15 15 0.15 20 0  "みなさんこんにちは、ゆっくり霊夢です"
yspeak 1 3 0 0 0 0 0 0 15 15 0.15 20 0  "ゆっくり魔理沙だぜ"
yspeak 2 3 0 0 0 0 0 0 15 15 0.15 20 0  "ゲストのゆっくり妖夢です。"
ywait 200 
yspeak 0 3 0 0 0 0 0 0 15 15 0.15 20 0  "以前UWSCでゆっくりムービーメーカー3のセリフ入力を自動化したけど、"
yspeak 0 3 0 0 0 0 0 0 15 15 0.15 20 0  "UIAutomationとPowerShellでもやってみたよ。"
ywait 200 
yspeak 1 3 0 0 0 0 0 0 15 15 0.15 20 0  "なんでまたムービーメーカー3で。"

###
# 省略
###
ywait 200 
yspeak 0 3 0 0 0 0 0 0 15 15 0.15 20 0  "それでは"
yspeak 0 3 0 0 0 0 0 0 15 15 0.15 20 0  "本日のご視聴ありがとうございました。"
yspeak 1 3 0 0 0 0 0 0 15 15 0.15 20 0  "本日のご視聴ありがとうございました。"
yspeak 2 3 0 0 0 0 0 0 15 15 0.15 20 0  "本日のご視聴ありがとうございました。"






exit




# 覚え書き
#$mainWindow.FindAll($UIAChildrenScope, $UIATrue)  | % {$_.current}  | select name, ControlType , ClassName, LocalizedControlType




エクセルで作った補助ツール
Book1

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください