forked from MaskedRetriever/papagayo-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LipsyncFrame.py
708 lines (647 loc) · 28.5 KB
/
LipsyncFrame.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
# -*- coding: ISO-8859-1 -*-
# generated by wxGlade 0.3.5.1 on Wed Apr 13 16:04:35 2005
# Papagayo, a lip-sync tool for use with Lost Marble's Moho
# Copyright (C) 2005 Mike Clifton
# Contact information at http://www.lostmarble.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import os
import string
import math
import wx
import webbrowser
from utilities import *
# begin wxGlade: dependencies
from MouthView import MouthView
from WaveformView import WaveformView
# end wxGlade
from AboutBox import AboutBox
from LipsyncDoc import *
appTitle = "Papagayo"
lipsyncExtension = ".pgo"
audioExtensions = "*.wav;*.mp3;*.aiff;*.aif;*.au;*.snd;*.mov;*.m4a"
openWildcard = "%s and sound files|*%s;%s" % (appTitle, lipsyncExtension, audioExtensions)
openAudioWildcard = "Sound files|%s" % (audioExtensions)
saveWildcard = "%s files (*%s)|*%s" % (appTitle, lipsyncExtension, lipsyncExtension)
class DigitOnlyValidator(wx.PyValidator):
def __init__(self, flag=None, pyVar=None):
wx.PyValidator.__init__(self)
self.Bind(wx.EVT_CHAR, self.OnChar)
def Clone(self):
return DigitOnlyValidator()
def Validate(self, win):
tc = self.GetWindow()
val = tc.GetValue()
for x in val:
if x not in string.digits:
return False
return True
def OnChar(self, event):
key = event.GetKeyCode()
if key < wx.WXK_SPACE or key == wx.WXK_DELETE or key > 255:
event.Skip()
return
if chr(key) in string.digits:
event.Skip()
return
# Returning without calling even.Skip eats the event before it
# gets to the text control
return
class LipsyncFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: LipsyncFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
#Voice List Box
self.panel_2 = wx.Panel(self, -1)
self.sizer_5_staticbox = wx.StaticBox(self.panel_2, -1, "Voice List")
self.sizer_7_staticbox = wx.StaticBox(self.panel_2, -1, "Current Voice")
# Menu Bar
self.mainFrame_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_OPEN, "&Open...\tCtrl+O", "Open a sound file or Papagayo project", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_SAVE, "&Save\tCtrl+S", "Save this lipsync project", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_SAVEAS, "Save &As...", "Save this Papagayo project under a new name", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_EXIT, "Exit", "Quit Papagayo", wx.ITEM_NORMAL)
self.mainFrame_menubar.Append(wxglade_tmp_menu, "&File")
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_UNDO, "&Undo\tCtrl+Z", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_CUT, "Cu&t\tCtrl+X", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_COPY, "&Copy\tCtrl+C", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_PASTE, "&Paste\tCtrl+V", "", wx.ITEM_NORMAL)
self.mainFrame_menubar.Append(wxglade_tmp_menu, "&Edit")
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_HELP, "&Help Topics", "Open the user's manual", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.ID_ABOUT, "&About Papagayo...", "Display information about Papagayo", wx.ITEM_NORMAL)
self.mainFrame_menubar.Append(wxglade_tmp_menu, "&Help")
self.SetMenuBar(self.mainFrame_menubar)
# Menu Bar end
self.mainFrame_statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
# Tool Bar
self.mainFrame_toolbar = wx.ToolBar(self, -1, style=wx.TB_HORIZONTAL|wx.TB_FLAT)
self.SetToolBar(self.mainFrame_toolbar)
global ID_PLAY; ID_PLAY = wx.NewId()
global ID_STOP; ID_STOP = wx.NewId()
global ID_ZOOMIN; ID_ZOOMIN = wx.NewId()
global ID_ZOOMOUT; ID_ZOOMOUT = wx.NewId()
global ID_ZOOM1; ID_ZOOM1 = wx.NewId()
global ID_CHORUS; ID_CHORUS = wx.NewId()
global ID_ABBREVIATE; ID_ABBREVIATE = wx.NewId()
self.mainFrame_toolbar.AddLabelTool(wx.ID_OPEN, "Open", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/open.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Open", "Open a sound file or Papagayo project")
self.mainFrame_toolbar.AddLabelTool(wx.ID_SAVE, "Save", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/save.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Save", "Save this Papagayo project")
self.mainFrame_toolbar.AddSeparator()
self.mainFrame_toolbar.AddLabelTool(ID_PLAY, "Play", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/play.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Play", "Play the sound clip")
self.mainFrame_toolbar.AddLabelTool(ID_STOP, "Stop", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/stop.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Stop", "Stop playing audio")
self.mainFrame_toolbar.AddSeparator()
self.mainFrame_toolbar.AddLabelTool(ID_ZOOMIN, "Zoom In", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/zoom_in.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Zoom In", "Zoom in on the waveform")
self.mainFrame_toolbar.AddLabelTool(ID_ZOOMOUT, "Zoom Out", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/zoom_out.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Zoom Out", "Zoom out of the waveform")
self.mainFrame_toolbar.AddLabelTool(ID_ZOOM1, "Reset Zoom", (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/zoom_1.png"))), wx.NullBitmap, wx.ITEM_NORMAL, "Reset Zoom", "Reset the zoomed view of the waveform")
self.mainFrame_toolbar.AddSeparator()
self.mainFrame_toolbar.AddCheckTool(ID_CHORUS, (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/chorus.png"))),wx.NullBitmap, "Chorus Mode","Toggle Playing All Voices")
self.mainFrame_toolbar.AddCheckTool(ID_ABBREVIATE, (wx.Bitmap(os.path.join(get_main_dir(),"rsrc/abbreviate.png"))),wx.NullBitmap, "Abbreviate Mode","Toggle Shorter Scrub Playback")
# Tool Bar end
self.waveformView = WaveformView(self.panel_2, -1)
self.label_2 = wx.StaticText(self.panel_2, -1, "Voice name:")
global ID_VOICENAME; ID_VOICENAME = wx.NewId()
self.voiceName = wx.TextCtrl(self.panel_2, ID_VOICENAME, "")
self.label_1 = wx.StaticText(self.panel_2, -1, "Spoken text:")
global ID_VOICETEXT; ID_VOICETEXT = wx.NewId()
self.voiceText = wx.TextCtrl(self.panel_2, ID_VOICETEXT, "", style=wx.TE_MULTILINE)
self.label_4 = wx.StaticText(self.panel_2, -1, "Phonetic breakdown:")
global ID_LANGUAGECHOICE; ID_LANGUAGECHOICE = wx.NewId()
self.languageChoice = wx.Choice(self.panel_2, ID_LANGUAGECHOICE, choices=[])
global ID_PHONEMESETCHOICE; ID_PHONEMESETCHOICE = wx.NewId()
self.phonemesetChoice = wx.Choice(self.panel_2, ID_PHONEMESETCHOICE, choices=[])
global ID_BREAKDOWN; ID_BREAKDOWN = wx.NewId()
self.breakdownBut = wx.Button(self.panel_2, ID_BREAKDOWN, "Breakdown")
global ID_RELOADDICT; ID_RELOADDICT = wx.NewId()
self.reloaddictBut = wx.Button(self.panel_2, ID_RELOADDICT, "Reload Dict")
global ID_EXPORTCHOICE; ID_EXPORTCHOICE = wx.NewId()
self.exportChoice = wx.Choice(self.panel_2, ID_EXPORTCHOICE, choices=[])
global ID_EXPORT; ID_EXPORT = wx.NewId()
self.exportBut = wx.Button(self.panel_2, ID_EXPORT, "Export...")
global ID_VOICEIMAGE; ID_VOICEIMAGE = wx.NewId()
self.voiceimageBut = wx.Button(self.panel_2,ID_VOICEIMAGE,"Image to Export")
self.label_3 = wx.StaticText(self.panel_2, -1, "Fps:")
global ID_FPS; ID_FPS = wx.NewId()
self.fpsCtrl = wx.TextCtrl(self.panel_2, ID_FPS, "")
global ID_MOUTHCHOICE; ID_MOUTHCHOICE = wx.NewId()
self.mouthChoice = wx.Choice(self.panel_2, ID_MOUTHCHOICE, choices=[])
self.mouthView = MouthView(self.panel_2, -1)
global ID_VOICELIST; ID_VOICELIST = wx.NewId()
self.voiceList = wx.ListBox(self.panel_2, ID_VOICELIST, choices=[])
global ID_NEWVOICE; ID_NEWVOICE = wx.NewId()
self.newVoiceBut = wx.Button(self.panel_2, ID_NEWVOICE, "New")
global ID_DELVOICE; ID_DELVOICE = wx.NewId()
self.delVoiceBut = wx.Button(self.panel_2, ID_DELVOICE, "Delete")
self.__set_properties()
self.__do_layout()
# end wxGlade
# Other initialization
self.SetMinSize(wx.Size(500, 450))
self.fpsCtrl.SetValidator(DigitOnlyValidator())
self.waveformView.mouthView = self.mouthView
self.doc = None
self.OnClose()
mouthList = self.mouthView.mouths.keys()
mouthList.sort()
for mouth in mouthList:
self.mouthChoice.Append(mouth)
self.mouthChoice.SetSelection(0)
self.mouthView.currentMouth = self.mouthChoice.GetStringSelection()
# setup language initialisation here
self.langman = LanguageManager()
self.langman.InitLanguages()
languageList = self.langman.language_table.keys()
languageList.sort()
c = 0
select = 0
for language in languageList:
self.languageChoice.Append(language)
if language == "English":
select = c
c += 1
self.languageChoice.SetSelection(select)
# setup phonemeset initialisation here
self.phonemeset = PhonemeSet()
for name in self.phonemeset.alternatives:
self.phonemesetChoice.Append(name)
self.phonemesetChoice.SetSelection(0)
#setup export intialization here
exporterList = ["MOHO", "ALELO", "Images"]
c = 0
select = 0
for exporter in exporterList:
self.exportChoice.Append(exporter)
if exporter == "MOHO":
select = c
c += 1
self.exportChoice.SetSelection(select)
self.ignoreTextChanges = False
self.config = wx.Config("Papagayo", "Lost Marble")
# Connect event handlers
global ID_PLAY_TICK; ID_PLAY_TICK = wx.NewId()
# window events
wx.EVT_CLOSE(self, self.CloseOK)
wx.EVT_TIMER(self, ID_PLAY_TICK, self.OnPlayTick)
# menus
wx.EVT_MENU(self, wx.ID_OPEN, self.OnOpen)
wx.EVT_MENU(self, wx.ID_SAVE, self.OnSave)
wx.EVT_MENU(self, wx.ID_SAVEAS, self.OnSaveAs)
wx.EVT_MENU(self, wx.ID_EXIT, self.OnQuit)
wx.EVT_MENU(self, wx.ID_HELP, self.OnHelp)
wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
# tools
wx.EVT_TOOL(self, ID_PLAY, self.OnPlay)
wx.EVT_TOOL(self, ID_STOP, self.OnStop)
wx.EVT_TOOL(self, ID_ZOOMIN, self.waveformView.OnZoomIn)
wx.EVT_TOOL(self, ID_ZOOMOUT, self.waveformView.OnZoomOut)
wx.EVT_TOOL(self, ID_ZOOM1, self.waveformView.OnZoom1)
wx.EVT_TOOL(self, ID_CHORUS, self.mouthView.ToggleChorus)
wx.EVT_TOOL(self, ID_ABBREVIATE, self.waveformView.ToggleAbbreviate)
# voice settings
wx.EVT_CHOICE(self, ID_MOUTHCHOICE, self.OnMouthChoice)
wx.EVT_TEXT(self, ID_VOICENAME, self.OnVoiceName)
wx.EVT_TEXT(self, ID_VOICETEXT, self.OnVoiceText)
wx.EVT_BUTTON(self, ID_BREAKDOWN, self.OnVoiceBreakdown)
wx.EVT_BUTTON(self, ID_RELOADDICT, self.OnReloadDictionary)
wx.EVT_BUTTON(self, ID_EXPORT, self.OnVoiceExport)
wx.EVT_BUTTON(self, ID_VOICEIMAGE, self.OnVoiceimagechoose)
wx.EVT_TEXT(self, ID_FPS, self.OnFps)
wx.EVT_LISTBOX(self, ID_VOICELIST, self.OnSelVoice)
wx.EVT_BUTTON(self, ID_NEWVOICE, self.OnNewVoice)
wx.EVT_BUTTON(self, ID_DELVOICE, self.OnDelVoice)
def __del__(self):
self.config.Flush()
def __set_properties(self):
# begin wxGlade: LipsyncFrame.__set_properties
self.SetTitle("Papagayo")
_icon = wx.EmptyIcon()
_icon.CopyFromBitmap(wx.Bitmap(os.path.join(get_main_dir(),"rsrc/window_icon.bmp")))
self.SetIcon(_icon)
self.SetSize((848, 566))
self.mainFrame_statusbar.SetStatusWidths([-1, 96])
# statusbar fields
mainFrame_statusbar_fields = ["Papagayo", "Stopped"]
for i in range(len(mainFrame_statusbar_fields)):
self.mainFrame_statusbar.SetStatusText(mainFrame_statusbar_fields[i], i)
self.mainFrame_toolbar.SetToolBitmapSize((16, 16))
self.mainFrame_toolbar.Realize()
self.voiceText.SetMinSize((128,128))
self.voiceList.SetMinSize((195, 133))
# end wxGlade
def __do_layout(self):
# begin wxGlade: LipsyncFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.BoxSizer(wx.VERTICAL)
sizer_5 = wx.StaticBoxSizer(self.sizer_5_staticbox, wx.VERTICAL)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
sizer_10 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.VERTICAL)
sizer_7 = wx.StaticBoxSizer(self.sizer_7_staticbox, wx.VERTICAL)
sizer_9 = wx.BoxSizer(wx.HORIZONTAL)
sizer_8 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3.Add(self.waveformView, 1, wx.EXPAND, 0)
sizer_8.Add(self.label_2, 0, wx.ALIGN_CENTER_VERTICAL|wx.FIXED_MINSIZE, 0)
sizer_8.Add((8, 8), 0, wx.ALIGN_CENTER_VERTICAL|wx.FIXED_MINSIZE, 0)
sizer_8.Add(self.voiceName, 0, wx.ALIGN_CENTER_VERTICAL|wx.FIXED_MINSIZE, 0)
sizer_7.Add(sizer_8, 0, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND, 4)
sizer_7.Add(self.label_1, 0, wx.LEFT|wx.TOP|wx.FIXED_MINSIZE, 4)
sizer_7.Add(self.voiceText, 1, wx.LEFT|wx.RIGHT|wx.TOP|wx.EXPAND|wx.FIXED_MINSIZE, 4)
sizer_7.SetItemMinSize(2, (120,120)) # Workaround bug for Ubuntu 11.10 and above
sizer_7.Add(self.label_4, 0, wx.LEFT|wx.TOP|wx.FIXED_MINSIZE, 4)
sizer_9.Add(self.languageChoice, 0, 0, 0)
sizer_9.Add((2, 2), 0, 0, 0)
sizer_9.Add(self.phonemesetChoice, 0, 0, 0)
sizer_9.Add((5, 5), 0, 0, 0)
sizer_9.Add(self.breakdownBut, 0, wx.FIXED_MINSIZE, 0)
sizer_9.Add(self.reloaddictBut, 0, 0, 0)
sizer_9.Add((5, 5), 1, wx.FIXED_MINSIZE, 0)
sizer_9.Add(self.exportChoice, 0, 0, 0)
sizer_9.Add((5, 5), 0, 0, 0)
sizer_9.Add(self.exportBut, 0, wx.FIXED_MINSIZE, 0)
sizer_9.Add((5,5),0,0,0)
sizer_9.Add(self.voiceimageBut, 0,wx.FIXED_MINSIZE, 0)
sizer_7.Add(sizer_9, 0, wx.ALL|wx.EXPAND, 4)
sizer_3.Add(sizer_7, 0, wx.ALL|wx.EXPAND, 4)
sizer_2.Add(sizer_3, 1, wx.EXPAND, 0)
sizer_10.Add(self.label_3, 0, wx.ALIGN_CENTER_VERTICAL|wx.FIXED_MINSIZE, 0)
sizer_10.Add((8, 8), 0, wx.ALIGN_CENTER_VERTICAL|wx.FIXED_MINSIZE, 0)
sizer_10.Add(self.fpsCtrl, 0, wx.FIXED_MINSIZE, 0)
sizer_4.Add(sizer_10, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
sizer_4.Add(self.mouthChoice, 0, wx.LEFT|wx.RIGHT|wx.BOTTOM|wx.EXPAND|wx.FIXED_MINSIZE, 4)
sizer_4.Add(self.mouthView, 0, wx.EXPAND, 0)
sizer_5.Add(self.voiceList, 1, wx.ALL|wx.EXPAND|wx.FIXED_MINSIZE, 4)
sizer_6.Add(self.newVoiceBut, 0, wx.FIXED_MINSIZE, 0)
sizer_6.Add((20, 20), 0, wx.FIXED_MINSIZE, 0)
sizer_6.Add(self.delVoiceBut, 0, wx.FIXED_MINSIZE, 0)
sizer_5.Add(sizer_6, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 4)
sizer_4.Add(sizer_5, 1, wx.ALL|wx.EXPAND, 4)
sizer_2.Add(sizer_4, 0, wx.LEFT|wx.EXPAND, 4)
self.panel_2.SetSizer(sizer_2)
sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
self.Layout()
self.Centre()
# end wxGlade
def CloseOK(self, event):
if not event.CanVeto():
self.OnClose()
event.Skip()
return
if not self.CloseDocOK():
event.Veto()
return
self.OnClose()
event.Skip()
def CloseDocOK(self):
if self.doc is not None:
if not self.doc.dirty:
return True
dlg = wx.MessageDialog(self, 'Save changes to this project?', appTitle,
wx.YES_NO | wx.CANCEL | wx.YES_DEFAULT | wx.ICON_QUESTION)
result = dlg.ShowModal()
dlg.Destroy()
if result == wx.ID_YES:
self.OnSave()
if not self.doc.dirty:
self.config.Write("LastFPS", `self.doc.fps`)
return True
else:
return False
elif result == wx.ID_NO:
self.config.Write("LastFPS", `self.doc.fps`)
return True
elif result == wx.ID_CANCEL:
return False
else:
return True
def OnOpen(self, event = None):
if not self.CloseDocOK():
return
dlg = wx.FileDialog(
self, message = "Open Audio or %s File" % appTitle, defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "", wildcard = openWildcard, style = wx.OPEN | wx.CHANGE_DIR | wx.FILE_MUST_EXIST)
if dlg.ShowModal() == wx.ID_OK:
self.OnStop()
self.OnClose()
self.config.Write("WorkingDir", dlg.GetDirectory())
paths = dlg.GetPaths()
self.Open(paths[0])
dlg.Destroy()
def Open(self, path):
self.doc = LipsyncDoc(self.langman, self)
if path.endswith(lipsyncExtension):
# open a lipsync project
self.doc.Open(path)
while self.doc.sound is None:
# if no sound file found, then ask user to specify one
dlg = wx.MessageDialog(self, 'Please load correct audio file', appTitle,
wx.OK | wx.ICON_WARNING)
result = dlg.ShowModal()
dlg.Destroy()
dlg = wx.FileDialog(
self, message = "Open Audio", defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "", wildcard = openAudioWildcard, style = wx.OPEN | wx.CHANGE_DIR | wx.FILE_MUST_EXIST)
if dlg.ShowModal() == wx.ID_OK:
self.config.Write("WorkingDir", dlg.GetDirectory())
paths = dlg.GetPaths()
self.doc.OpenAudio(paths[0])
dlg.Destroy()
else:
# open an audio file
self.doc.fps = int(self.config.Read("LastFPS", `24`))
self.doc.OpenAudio(path)
if self.doc.sound is None:
self.doc = None
else:
self.doc.voices.append(LipsyncVoice("Voice 1"))
self.doc.currentVoice = self.doc.voices[0]
# check for a .trans file with the same name as the doc
try:
txtFile = file(paths[0].rsplit('.', 1)[0]+".trans", 'r')
for line in txtFile:
self.voiceText.AppendText(line)
except:
pass
if self.doc is not None:
self.SetTitle("%s [%s] - %s" % (self.doc.name, path, appTitle))
self.waveformView.SetDocument(self.doc)
self.mouthView.SetDocument(self.doc)
# menus
self.mainFrame_menubar.Enable(wx.ID_SAVE, True)
self.mainFrame_menubar.Enable(wx.ID_SAVEAS, True)
# toolbar buttons
self.mainFrame_toolbar.EnableTool(wx.ID_SAVE, True)
if self.doc.sound is not None:
self.mainFrame_toolbar.EnableTool(ID_PLAY, True)
self.mainFrame_toolbar.EnableTool(ID_ZOOMIN, True)
self.mainFrame_toolbar.EnableTool(ID_ZOOMOUT, True)
self.mainFrame_toolbar.EnableTool(ID_ZOOM1, True)
# voice list
self.voiceList.Enable(True)
self.newVoiceBut.Enable(True)
self.delVoiceBut.Enable(True)
for voice in self.doc.voices:
self.voiceList.Insert(voice.name, self.voiceList.GetCount())
self.voiceList.SetSelection(0)
# voice controls
self.fpsCtrl.Enable(True)
self.fpsCtrl.SetValue(str(self.doc.fps))
self.voiceName.Enable(True)
self.voiceName.SetValue(self.doc.currentVoice.name)
self.voiceText.Enable(True)
self.voiceText.SetValue(self.doc.currentVoice.text)
self.languageChoice.Enable(True)
self.phonemesetChoice.Enable(True)
self.breakdownBut.Enable(True)
self.reloaddictBut.Enable(True)
self.exportChoice.Enable(True)
self.exportBut.Enable(True)
self.voiceimageBut.Enable(True)
def OnSave(self, event = None):
if self.doc is None:
return
if self.doc.path is None:
self.OnSaveAs()
return
self.doc.Save(self.doc.path)
def OnSaveAs(self, event = None):
if self.doc is None:
return
dlg = wx.FileDialog(
self, message = "Save %s File" % appTitle, defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "%s" % self.doc.soundPath.rsplit('.', 1)[0]+".pgo", wildcard = saveWildcard, style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
self.config.Write("WorkingDir", dlg.GetDirectory())
self.doc.Save(dlg.GetPaths()[0])
self.SetTitle("%s [%s] - %s" % (self.doc.name, dlg.GetPaths()[0], appTitle))
dlg.Destroy()
def OnClose(self):
if self.doc is not None:
self.config.Write("LastFPS", `self.doc.fps`)
del self.doc
self.doc = None
self.waveformView.SetDocument(self.doc)
# menus
self.mainFrame_menubar.Enable(wx.ID_SAVE, False)
self.mainFrame_menubar.Enable(wx.ID_SAVEAS, False)
# toolbar buttons
self.mainFrame_toolbar.EnableTool(wx.ID_SAVE, False)
self.mainFrame_toolbar.EnableTool(ID_PLAY, False)
self.mainFrame_toolbar.EnableTool(ID_STOP, False)
self.mainFrame_toolbar.EnableTool(ID_ZOOMIN, False)
self.mainFrame_toolbar.EnableTool(ID_ZOOMOUT, False)
self.mainFrame_toolbar.EnableTool(ID_ZOOM1, False)
# voice controls
self.voiceName.Clear()
self.voiceName.Enable(False)
self.voiceText.Clear()
self.voiceText.Enable(False)
self.languageChoice.Enable(False)
self.phonemesetChoice.Enable(False)
self.breakdownBut.Enable(False)
self.reloaddictBut.Enable(False)
self.exportChoice.Enable(False)
self.exportBut.Enable(False)
self.voiceimageBut.Enable(False)
# voice list
self.fpsCtrl.Clear()
self.fpsCtrl.Enable(False)
self.voiceList.Clear()
self.voiceList.Enable(False)
self.newVoiceBut.Enable(False)
self.delVoiceBut.Enable(False)
def OnQuit(self, event = None):
self.OnClose()
self.Close(True)
def OnHelp(self, event = None):
webbrowser.open("file://%s" % os.path.join(get_main_dir(), "help/index.html"))
def OnAbout(self, event = None):
dlg = AboutBox(self)
dlg.ShowModal()
dlg.Destroy()
def OnPlay(self, event = None):
if (self.doc is not None) and (self.doc.sound is not None):
self.curFrame = -1
self.mainFrame_toolbar.EnableTool(ID_PLAY, False)
self.mainFrame_toolbar.EnableTool(ID_STOP, True)
self.doc.sound.SetCurTime(0)
self.doc.sound.Play(False)
self.timer = wx.Timer(self, ID_PLAY_TICK)
self.timer.Start(250.0 / self.doc.fps)
def OnStop(self, event = None):
if (self.doc is not None) and (self.doc.sound is not None):
self.doc.sound.Stop()
self.doc.sound.SetCurTime(0)
self.mouthView.SetFrame(0)
self.waveformView.SetFrame(0)
self.mainFrame_toolbar.EnableTool(ID_PLAY, True)
self.mainFrame_toolbar.EnableTool(ID_STOP, False)
self.mainFrame_statusbar.SetStatusText("Stopped", 1)
def OnPlayTick(self, event):
if (self.doc is not None) and (self.doc.sound is not None):
if self.doc.sound.IsPlaying():
curFrame = int(math.floor(self.doc.sound.CurrentTime() * self.doc.fps))
if curFrame != self.curFrame:
self.curFrame = curFrame
self.mouthView.SetFrame(self.curFrame)
self.waveformView.SetFrame(self.curFrame)
self.mainFrame_statusbar.SetStatusText("Frame: %d" % (curFrame + 1), 1)
else:
self.OnStop()
self.timer.Stop()
del self.timer
def OnMouthChoice(self, event):
self.mouthView.currentMouth = self.mouthChoice.GetStringSelection()
self.mouthView.DrawMe()
def OnVoiceName(self, event):
if (self.doc is not None) and (self.doc.currentVoice is not None):
self.doc.dirty = True
self.doc.currentVoice.name = self.voiceName.GetValue()
self.voiceList.SetString(self.voiceList.GetSelection(), self.doc.currentVoice.name)
def OnVoiceText(self, event):
if self.ignoreTextChanges:
return
if (self.doc is not None) and (self.doc.currentVoice is not None):
self.doc.dirty = True
self.doc.currentVoice.text = self.voiceText.GetValue()
def OnVoiceBreakdown(self, event = None):
if (self.doc is not None) and (self.doc.currentVoice is not None):
language = self.languageChoice.GetStringSelection()
phonemeset_name = self.phonemesetChoice.GetStringSelection()
self.phonemeset.Load(phonemeset_name)
self.doc.dirty = True
self.doc.currentVoice.RunBreakdown(self.doc.soundDuration, self, language, self.langman, self.phonemeset)
self.waveformView.UpdateDrawing()
self.ignoreTextChanges = True
self.voiceText.SetValue(self.doc.currentVoice.text)
self.ignoreTextChanges = False
def OnVoiceExport(self, event):
language = self.languageChoice.GetStringSelection()
if (self.doc is not None) and (self.doc.currentVoice is not None):
exporter = self.exportChoice.GetStringSelection()
if exporter == "MOHO":
dlg = wx.FileDialog(
self, message = "Export Lipsync Data (MOHO)", defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "%s" % self.doc.soundPath.rsplit('.', 1)[0]+".dat", wildcard = "Moho switch files (*.dat)|*.dat", style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
self.config.Write("WorkingDir", dlg.GetDirectory())
self.doc.currentVoice.Export(dlg.GetPaths()[0])
dlg.Destroy()
elif exporter == "ALELO":
fps = int(self.fpsCtrl.GetValue())
if fps != 100:
dlg = wx.MessageDialog(self, 'FPS is NOT 100 continue? (You will have issues downstream.)', appTitle,
wx.YES_NO | wx.CANCEL | wx.YES_DEFAULT | wx.ICON_WARNING)
result = dlg.ShowModal()
dlg.Destroy()
else:
result = wx.ID_YES
if result == wx.ID_YES:
dlg = wx.FileDialog(
self, message = "Export Lipsync Data (ALELO)", defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "%s" % self.doc.soundPath.rsplit('.', 1)[0]+".txt", wildcard = "Alelo timing files (*.txt)|*.txt", style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
if dlg.ShowModal() == wx.ID_OK:
self.config.Write("WorkingDir", dlg.GetDirectory())
self.doc.currentVoice.ExportAlelo(dlg.GetPaths()[0], language, self.langman)
dlg.Destroy()
elif exporter == "Images":
dlg = wx.FileDialog(
self, message = "Export Image Strip", defaultDir = self.config.Read("WorkingDir", get_main_dir()),
defaultFile = "%s" % self.doc.soundPath.rsplit('.', 1)[0], style = wx.SAVE | wx.CHANGE_DIR | wx.OVERWRITE_PROMPT)
if dlg.ShowModal() ==wx.ID_OK:
self.config.Write("WorkingDir", dlg.GetDirectory())
self.doc.currentVoice.ExportImages(dlg.GetPaths()[0],self.mouthChoice.GetStringSelection())
dlg.Destroy()
def OnVoiceimagechoose(self, event):
language = self.languageChoice.GetStringSelection()
if (self.doc is not None) and (self.doc.currentVoice is not None):
voiceimagepath = wx.DirDialog(
self, message = "Choose Path for Images", defaultPath = self.config.Read("MouthDir", os.path.join(os.path.dirname(os.path.abspath(__file__)), "rsrc/mouths/")),
style = wx.OPEN | wx.CHANGE_DIR | wx.DD_DIR_MUST_EXIST)
if voiceimagepath.ShowModal() ==wx.ID_OK:
self.config.Write("MouthDir",voiceimagepath.GetPath())
print(voiceimagepath.GetPath())
voiceimagepath.Destroy()
def OnFps(self, event):
if self.doc is None:
return
try:
newFps = int(self.fpsCtrl.GetValue())
except:
newFps = self.doc.fps
if newFps == self.doc.fps:
return
self.doc.dirty = True
self.doc.fps = newFps
if self.doc.fps < 1:
self.doc.fps = 1
if self.doc.fps > 120:
self.doc.fps = 120
# refresh the document properties
self.doc.OpenAudio(self.doc.soundPath)
self.waveformView.SetDocument(None)
self.waveformView.SetDocument(self.doc)
self.mouthView.DrawMe()
def OnSelVoice(self, event):
if self.doc is None:
return
self.ignoreTextChanges = True
self.doc.currentVoice = self.doc.voices[self.voiceList.GetSelection()]
self.voiceName.SetValue(self.doc.currentVoice.name)
self.voiceText.SetValue(self.doc.currentVoice.text)
self.ignoreTextChanges = False
self.waveformView.UpdateDrawing()
self.mouthView.DrawMe()
def OnNewVoice(self, event):
if self.doc is None:
return
self.doc.dirty = True
self.doc.voices.append(LipsyncVoice("Voice %d" % (len(self.doc.voices) + 1)))
self.doc.currentVoice = self.doc.voices[-1]
self.voiceList.Insert(self.doc.currentVoice.name, self.voiceList.GetCount())
self.voiceList.SetSelection(self.voiceList.GetCount() - 1)
self.ignoreTextChanges = True
self.voiceName.SetValue(self.doc.currentVoice.name)
self.voiceText.SetValue(self.doc.currentVoice.text)
self.ignoreTextChanges = False
self.waveformView.UpdateDrawing()
self.mouthView.DrawMe()
def OnDelVoice(self, event):
if (self.doc is None) or (len(self.doc.voices) == 1):
return
self.doc.dirty = True
newIndex = self.doc.voices.index(self.doc.currentVoice)
if newIndex > 0:
newIndex -= 1
else:
newIndex = 0
self.doc.voices.remove(self.doc.currentVoice)
self.doc.currentVoice = self.doc.voices[newIndex]
self.voiceList.Clear()
for voice in self.doc.voices:
self.voiceList.Insert(voice.name, self.voiceList.GetCount())
self.voiceList.SetSelection(newIndex)
self.voiceName.SetValue(self.doc.currentVoice.name)
self.voiceText.SetValue(self.doc.currentVoice.text)
self.waveformView.UpdateDrawing()
self.mouthView.DrawMe()
def OnReloadDictionary(self, event):
print "reload the dictionary"
lang_config = self.doc.language_manager.language_table[self.languageChoice.GetStringSelection()]
self.doc.language_manager.LoadLanguage(lang_config,force=True)
# end of class LipsyncFrame