Add a class for incrementally tracking tokenization of a statement
[reinteract/rox.git] / lib / replay.py
blobe0167a2b61121998d7a903468dc91004013f65aa
1 import gtk
2 import os
4 from numpy import float32, float64
6 from reinteract.custom_result import CustomResult
8 class PlayResult(CustomResult):
9 def __init__(self, data):
10 self.__data = data
12 def create_widget(self):
13 widget = gtk.Button("Play")
14 widget.connect('clicked', self.play)
16 return widget
18 def play(self, *args):
19 if self.__data.dtype == float32:
20 command = 'play -t raw -r 44100 -f -4 -L -q -'
21 else:
22 command = 'play -t raw -r 44100 -f -8 -L -q -'
24 f = os.popen(command, 'w')
25 self.__data.tofile(f)
26 f.close()
28 def play(data):
29 if data.dtype != float32 and data.dtype != float64:
30 raise TypeError("Data must be float32 or float64, not %s", data.dtype)
32 return PlayResult(data)