comparison scripts/regen-speech.py @ 109:66898d810247

Add hackish speech support (run regen-speech.py to generate files -- needs espeak and oggenc).
author Simon Cross <simon@simonx>
date Tue, 24 Aug 2010 14:32:52 +0200
parents
children 1b1ab71535bd
comparison
equal deleted inserted replaced
108:ab11689aec36 109:66898d810247
1 #!/usr/bin/env python
2
3 import pygame
4 import subprocess
5 import os
6
7 from gamelib.state import initial_state
8 from gamelib import speech
9
10 from albow.resource import resource_path
11
12 from pygame.locals import SWSURFACE
13 from gamelib.constants import SCREEN
14
15 # We need this stuff set up so we can load images and whatnot.
16 pygame.display.init()
17 pygame.display.set_mode(SCREEN, SWSURFACE)
18
19
20 def espeak(text, filename, voice="en-sc"):
21 """Call espeak. Use espeak --voices for list of voices."""
22 tmpfile = "%s.wav" % filename
23 stdout = open(tmpfile, "wb")
24 subprocess.call(["espeak", "--stdout", "-v", voice, text], stdout=stdout)
25 print ["oggenc", tmpfile, "-o", filename]
26 subprocess.call(["oggenc", tmpfile, "-o", filename])
27 os.remove(tmpfile)
28
29
30 def main():
31 state = initial_state()
32 for scene in state.scenes.values():
33 for thing in scene.things.values():
34 texts = getattr(thing, "SPEECH", None)
35 if texts is None:
36 continue
37 for text in texts:
38 filename = speech.get_filename(thing.name, text)
39 filename = resource_path("sounds", "speech", filename)
40 print "[%s: %s] -> %s" % (thing.name, text[:30], filename)
41 espeak(text, filename)
42
43
44 if __name__ == "__main__":
45 main()