Skip to content

Instantly share code, notes, and snippets.

@sskwwskwww
Last active Jun 12, 2017
Embed
What would you like to do?
VOICEROID2を外部から読み上げさせる奴
Option Strict Off
Imports Codeer.Friendly.Windows
Imports Codeer.Friendly.Windows.Grasp
Imports RM.Friendly.WPFStandardControls
Imports System.Windows.Controls
Imports Codeer.Friendly.Windows.NativeStandardControls
Imports Codeer.Friendly
Public Class VoiceRoid2
'定数
Private Const TIMEOUT As Integer = 5000 'タイムアウトms
Private Const WAITTIME As Integer = 5 'ループ中待機時間ms
'プロセス名
Private Const PROCESS_NAME As String = "VoiceroidEditor"
'使用変数
Private p As Process = Nothing
'コンストラクタ
Public Sub New()
Refresh()
End Sub
'存在チェック
Public Function Exists() As Boolean
Dim plist() As Process = Process.GetProcessesByName(PROCESS_NAME)
If plist.Count = 0 Then
p = Nothing
Return False
End If
p = plist(0)
Return True
End Function
'再検索
'成功した場合True
Public Function Refresh() As Boolean
If Not Exists() Then
Return False
End If
'毎回情報取得してるが、ここで予め取得しておくべきか
'成功
Return True
End Function
Public Function Play(ByVal text As String) As Boolean
'存在チェック
If Not Exists() Then
Return False
End If
'メイン
Dim main As WindowControl = WindowControl.FromZTop(New WindowsAppFriend(p))
'データ取得
Dim tb As New WPFTextBox(main.LogicalTree().ByType(Of TextBox).Item(0))
Dim playbtn As WPFButtonBase = Nothing
Dim savebtn As WPFButtonBase = Nothing
Dim btnlist = main.LogicalTree().ByType(Of Button)
Dim count As Integer = btnlist.Count - 1
For i As Integer = 0 To count
Dim btn As New WPFButtonBase(btnlist.Item(i))
Dim btblist = btn.LogicalTree(TreeRunDirection.Descendants).ByType(Of TextBlock)
If btblist.Count = 1 Then
Dim btb As New WPFTextBlock(btblist.Single)
If playbtn Is Nothing AndAlso btb.Text = "再生" Then
playbtn = New WPFButtonBase(btnlist.Item(i))
ElseIf savebtn Is Nothing AndAlso btb.Text = "音声保存" Then
savebtn = New WPFButtonBase(btnlist.Item(i))
End If
End If
Next
'再生完了待機
Do
If savebtn.IsEnabled Then
Exit Do
End If
Threading.Thread.Sleep(WAITTIME)
Loop
'再生
tb.EmulateChangeText(text)
Dim async As New Async
playbtn.EmulateClick(async)
Dim alertwindow As WindowControl = main.WaitForNextModal(async)
If Not async.IsCompleted Then
Dim alert As New NativeMessageBox(alertwindow)
alert.EmulateButtonClick("はい(&Y)")
Try
async.WaitForCompletion()
Catch ex As Exception
End Try
End If
'再生完了待機
Dim sw As New Stopwatch
sw.Start()
While sw.ElapsedMilliseconds < TIMEOUT
If Not savebtn.IsEnabled Then
Do
If savebtn.IsEnabled Then
Exit While
End If
Threading.Thread.Sleep(WAITTIME)
Loop
End If
Threading.Thread.Sleep(WAITTIME)
End While
'成功
Return True
End Function
'プリセット一覧取得
Public Function GetPresetList() As List(Of String)
Dim ret As New List(Of String)
'存在チェック
If Not Exists() Then
Return ret
End If
'メイン
Dim main As WindowControl = WindowControl.FromZTop(New WindowsAppFriend(p))
'情報取得
Dim tc As New WPFTabControl(main.LogicalTree().ByType(Of TabControl).Item(0))
Dim lvlist = tc.LogicalTree(TreeRunDirection.Descendants).ByType(Of System.Windows.Controls.ListView)
Dim lvcount As Integer = lvlist.Count - 1
For i As Integer = 0 To lvcount
Dim lv As New WPFListView(lvlist.Item(i))
Dim itemcount As Integer = lv.ItemCount - 1
For j As Integer = 0 To itemcount
Dim ltb As New WPFTextBlock(lv.GetItem(j).VisualTree(TreeRunDirection.Descendants).ByType(Of TextBlock).Item(1))
ret.Remove(ltb.Text) '重複名排除
ret.Add(ltb.Text)
Next
Next
'結果を返す
Return ret
End Function
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment