示例#1
0
def _test11():
    # A reduced version of test10
    ret = ""
    # GmmMgr setup

    num_states = 2
    dimension = 2
    models = []
    for i in xrange(num_states):
        dm = DummyModel(dimension, 1.0)
        models.append(dm)

    gmm_mgr = GmmMgr(models)

    gb = GraphBuilder()
    node_id0 = gb.new_node((0, 0))
    node_id1 = gb.new_node((1, 1))
    node_id2 = gb.new_node((2, 1))
    node_id3 = gb.new_node((3, 1))
    node_id4 = gb.new_node((4, 2))

    # The topology here is slightly complex than the previous example
    arc_id = gb.new_arc(node_id0, node_id1)
    arc_id = gb.new_arc(node_id1, node_id4)
    arc_id = gb.new_arc(node_id0, node_id2)
    arc_id = gb.new_arc(node_id2, node_id3)
    arc_id = gb.new_arc(node_id3, node_id4)
    arc_id = gb.new_arc(node_id2, node_id4)
    gr0 = FrozenGraph(gb)

    # Make two Hmms with 3 states and order 2 (self loop, forward 1)
    # The models in the middle are special and can skip.
    seed(0)
    hmm0 = make_forward_hmm(gmm_mgr, num_states, order=2, exact=False)
    hmm1 = Hmm(1)
    trans = array(((0.0, 0.5, 0.5), (0.0, 0.5, 0.5), (0.0, 0.0, 0.0)))
    hmm1.build_model(gmm_mgr, (0, ), 1, 1, trans)
    hmm2 = make_forward_hmm(gmm_mgr, num_states, order=2, exact=True)
    hmm_mgr = HmmMgr((hmm0, hmm1, hmm2))

    spd = {}
    spd[(0, 1)] = (0.4, )
    spd[(0, 2)] = (0.6, )

    spd[(2, 3)] = (0.4, )
    spd[(2, 4)] = (0.6, )

    tg0 = TrainingGraph(gr0, hmm_mgr, split_prob_dict=spd)

    if do_display:
        tg0.dot_display()
        tg0.dot_display(expand_hmms=True)

    with DebugPrint("bwt_ctsh") if True else DebugPrint():
        result_hmm = tg0.convert_to_standalone_hmm()
    ret += "\n\n========= TG CONVERTED TO Hmm =========\n\n" + result_hmm.to_string(
        full=True)

    return ret
示例#2
0
def on():
    utt.on
    utt.scale = 5
    prints = (
        #'gaussian',
        #'gaussian_pt',
        'SimpleGaussianTrainer',
        'ddt_accum',
        )
    db=DebugPrint(logstream, *prints)
    db.on()
    audio.on
示例#3
0
def _test9():
    # Like test8, but now HMMs have multiple inputs and outputs.
    ret = ""
    # GmmMgr setup

    num_states = 3
    dimension = 2
    models = []
    for i in xrange(num_states):
        dm = DummyModel(dimension, 1.0)
        models.append(dm)

    gmm_mgr = GmmMgr(models)

    gb = GraphBuilder()
    node_id0 = gb.new_node((0, 0))
    node_id1 = gb.new_node((1, 1))
    node_id2 = gb.new_node((2, 1))
    node_id3 = gb.new_node((3, 1))
    node_id4 = gb.new_node((4, 1))
    node_id5 = gb.new_node((5, 2))
    arc_id = gb.new_arc(node_id0, node_id1)
    arc_id = gb.new_arc(node_id1, node_id2)
    arc_id = gb.new_arc(node_id2, node_id3)
    arc_id = gb.new_arc(node_id3, node_id4)
    arc_id = gb.new_arc(node_id4, node_id5)
    gr0 = FrozenGraph(gb)

    # Make two Hmms with 3 states and order 3 (self loop, forward 1, forward 2)
    # The models in the middle are special and can skip directly
    seed(0)
    hmm0 = make_forward_hmm(gmm_mgr, num_states, order=3, exact=True)
    hmm1 = Hmm(1)
    trans = array(((0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
                    0.0), (0.0, 0.0, 0.0, 0.5, 0.0, 0.5,
                           0.0), (0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
                                  0.5), (0.0, 0.0, 0.0, 0.5, 0.35, 0.1, 0.05),
                   (0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                           0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)))
    hmm1.build_model(gmm_mgr, (0, ), 3, 3, trans)
    hmm2 = make_forward_hmm(gmm_mgr, num_states, order=3, exact=True)
    hmm_mgr = HmmMgr((hmm0, hmm1, hmm2))

    with DebugPrint("bwt_vrfy") if False else DebugPrint():
        tg0 = TrainingGraph(gr0, hmm_mgr, split_prob_dict=dict())

    result_hmm = tg0.convert_to_standalone_hmm()
    ret += "\n\n========= TG CONVERTED TO Hmm =========\n\n" + result_hmm.to_string(
        full=True)

    return ret
示例#4
0
def fifo_test():
    from time import sleep
    at = AccTracker(sending=False)

    right = ('A', ((1, 'A'), (0, 'B')))
    wrong = ('B', ((1, 'A'), (0, 'B')))
    input = tuple(([right]* 25 + [wrong] * 10) * 100)
    with open('/tmp/fifo.acc', 'w') as fifo:
        with DebugPrint(fifo, 'acc_track'):
            while 1:
                sleep(0.1)
                for item in input:
                    at.process(item)
示例#5
0
class DpToggle(object):
    """
    An object with two attributes, on and off, that toggle debug printing
    of the DebugPrint object created from the constructor args.
    """
    # XXX DebugPrint needs work to develop semantics to support multiple
    # instances of DpToggle....
    def __init__(self, *args):
        self.dp_control = DebugPrint(*args)
        self._on = False
    def __del__(self):
        self.off
    @property
    def on(self):
        if not self._on:
            self._on = True
            self.dp_control.on()
            return 'on'
    @property
    def off(self):
        if self._on:
            self._on = False
            self.dp_control.off()
            return 'off'
示例#6
0
def startup(args):
    global outfile
    global on, off, dp
    global start, stop
    global processor
    
    from functools import partial
    from onyx.audio.liveaudio import inputs, default_input, LiveAudioSource
    from onyx.signalprocessing.htkmfcc import make_fft_abs_processor
    from onyx.util.debugprint import DebugPrint, dcheck, dprint
    #from onyx.util.streamprocess import ChainProcessor

    if '-o' in args:
        outfile = open(args[args.index('-o')+1], 'wb', 0)
    else:
        outfile = sys.stdout

    if '-l' in args:
        logfile = open(args[args.index('-l')+1], 'wb', 0)
    else:
        logfile = sys.stdout

##     if '-m' in args:
##         mic_name = args[args.index('-m')+1]
##     else:
##         mic_name = 'blue'

    debug = DebugPrint(logfile, 'saddemo')

##     on = doer(debug.on)
##     off = doer(debug.off)
    dp = partial(dprint, 'saddemo', DebugPrint.NO_PREFIX, ' ')

    plot_points = 255
    line = [' '] * plot_points

##     # select a live input
##     mic_id = default_input()
##     for id, chan, name, manu in inputs():
##         if name.lower().find(mic_name.lower()) != -1:
##             mic_id = id
##             break
##     mic = LiveAudioSource(mic_id, verbose=False)    
##     start = doer(mic.start)
##     stop = doer(mic.stop)

    return

    # use the module's mic
    mic = audio.mic
    
    # XXX LiveAudioSource (and thus audiomodule.cpp) need to be able to provide
    # the sample frequency....
    sample_nsec =    22676  # 44100 Hz
    #frame_nsec =  10000000  # 10 msec
    #window_nsec = 25600000  # 25.6 msec
    frame_nsec =   8000000  #  8 msec
    window_nsec = 24000000  # 24 msec
    dither = 1 / (1 << 10)
    preemcoef = 0.96875
    samples_per_sec, fft_size, fftmag = make_fft_abs_processor(sample_nsec, frame_nsec, window_nsec,
                                                                dither=dither, preemcoef=preemcoef,
                                                                zmeansource=True, usehamming=True,
                                                                max_channels=2)

    print 'samples_per_sec', samples_per_sec, ' fft_size', fft_size

    # figure out range of fft bins to work with
    lowfreq = 300
    highfreq = 4000
    import math
    low_index = int(math.ceil(lowfreq * fft_size / samples_per_sec))
    high_index = int(math.floor(highfreq * fft_size / samples_per_sec))
    # the bin selector
    select = slice(low_index, high_index)
    def display(data):
        band = data[select]
        band *= band
        sum = float(band.sum())
        dB = int(dB_scale * (10 * math.log10(sum) + dB_offset))
        dp('%11.6f ' % sum, '%3d' % dB)
        dB = max(1, dB)
        #outfile.write('\n' + ' ' * dB + '|')
        outfile.write( pen * dB + 'O' + '\n')

    mic.set_sendee(fftmag.process)
    fftmag.set_sendee(display)
示例#7
0
 def __init__(self, *args):
     self.dp_control = DebugPrint(*args)
     self._on = False
示例#8
0
def _test10():
    # Like test9, but now HMMs are arranged in a diamond pattern so inter-HMM
    # probabilities come into play
    ret = ""
    # GmmMgr setup

    num_states = 3
    dimension = 2
    models = []
    for i in xrange(num_states):
        dm = DummyModel(dimension, 1.0)
        models.append(dm)

    gmm_mgr = GmmMgr(models)

    gb = GraphBuilder()
    node_id0 = gb.new_node((0, 0))
    node_id1 = gb.new_node((1, 1))
    node_id2 = gb.new_node((2, 1))
    node_id3 = gb.new_node((3, 1))
    node_id4 = gb.new_node((4, 1))
    node_id5 = gb.new_node((5, 2))

    # The topology here is more complex than previous examples
    arc_id = gb.new_arc(node_id0, node_id1)
    arc_id = gb.new_arc(node_id1, node_id5)
    arc_id = gb.new_arc(node_id0, node_id2)
    arc_id = gb.new_arc(node_id2, node_id3)
    arc_id = gb.new_arc(node_id3, node_id4)
    arc_id = gb.new_arc(node_id3, node_id5)
    arc_id = gb.new_arc(node_id4, node_id5)
    gr0 = FrozenGraph(gb)

    # Make two Hmms with 3 states and order 3 (self loop, forward 1, forward 2)
    # The models in the middle are special and can skip.
    seed(0)
    hmm0 = make_forward_hmm(gmm_mgr, num_states, order=3, exact=True)
    hmm1 = Hmm(1)
    trans = array(((0.0, 0.0, 0.0, 0.5, 0.5, 0.0,
                    0.0), (0.0, 0.0, 0.0, 0.5, 0.0, 0.5,
                           0.0), (0.0, 0.0, 0.0, 0.5, 0.0, 0.0,
                                  0.5), (0.0, 0.0, 0.0, 0.5, 0.35, 0.1, 0.05),
                   (0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                    0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
                           0.0), (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)))
    hmm1.build_model(gmm_mgr, (0, ), 3, 3, trans)
    hmm2 = make_forward_hmm(gmm_mgr, num_states, order=3, exact=True)
    hmm_mgr = HmmMgr((hmm0, hmm1, hmm2))

    spd = {}
    spd[(0, 1)] = (0.4, 0.3, 0.8)
    spd[(0, 2)] = (0.6, 0.7, 0.2)

    spd[(3, 4)] = (0.4, 0.3, 0.8)
    spd[(3, 5)] = (0.6, 0.7, 0.2)

    tg0 = TrainingGraph(gr0, hmm_mgr, split_prob_dict=spd)

    with DebugPrint("bwt_ctsh") if True else DebugPrint():
        result_hmm = tg0.convert_to_standalone_hmm()
    ret += "\n\n========= TG CONVERTED TO Hmm =========\n\n" + result_hmm.to_string(
        full=True)

    return ret
示例#9
0
        exit()

        numpy.set_printoptions(linewidth=300)

        ##         print "================================  TEST 0  ==========================="
        ##         with DebugPrint("bwt_ctsh", "hmm_gxfs", "hmm_da", "hmm_pofb", "hmm_poff") if True else DebugPrint():
        ##             s0 = test0(10)
        ##         print s0

        ##         print "================================  TEST 1  ==========================="
        ##         with DebugPrint("bwt_ctsh") if True else DebugPrint():
        ##             s1 = test1(10)
        ##         print s1

        ##         print "================================  TEST 2  ==========================="
        ##         s2 = test2(10)
        ##         print s2

        ##         print "================================  TEST 3  ==========================="
        ##         s3 = test3(10)
        ##         print s3

        ##         print "================================  TEST 4  ==========================="
        ##         s4 = test4(4, 10)
        ##         print s4
        print "================================  TEST 5  ==========================="
        with DebugPrint("bwt_ctsh", "hmm_gxfs", "hmm_da", "hmm_pofb",
                        "hmm_poff") if True else DebugPrint():
            s5 = test5(1, do_display=True)
        print s5