Menu

Loading another HMM model

Help
2017-04-17
2017-04-17
  • Tania Mendonca

    Tania Mendonca - 2017-04-17
     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
    #!/usr/bin/python
    
    from os import environ, path
    from glob import glob
    import os
    
    from pocketsphinx.pocketsphinx import *
    from sphinxbase.sphinxbase import *
    
    MODELDIR = "/home/tania/trial/sylabble"
    DATADIR = "/home/tania/trial/sylabble/wav/kannadatest_clstk"
    
    # Create a decoder with certain model
    config = Decoder.default_config()
    config.set_string('-hmm', path.join(MODELDIR, 'model_parameters/sylabble.cd_cont_200'))
    config.set_string('-lm', path.join(MODELDIR, 'etc/sylabble.lm.DMP'))
    config.set_string('-dict', path.join(MODELDIR, 'etc/sylabble.dic'))
    config.set_float('-beam', 1e-80)
    config.set_float('-fwdflatbeam', 1e-80)
    config.set_float('-fwdflatlw', 10)
    config.set_float('-fwdflatwbeam',1e-40)
    config.set_float('-lpbeam',1e-80)
    config.set_float('-lponlybeam',1e-80)
    config.set_float('-lw',10)
    config.set_float('-pbeam',1e-80)
    config.set_float('-wbeam',1e-40)
    config.set_float('-wip',2e-01)
    #config.set_string('-logfn', "/dev/null")
    i=0
    # Decode streaming data.
    decoder = Decoder(config)
    while i<2:
        decoder.start_utt()
        stream = open(path.join(DATADIR,'kan_0702.wav' ), 'rb')
        while True:
            buf = stream.read()
            if buf:
                decoder.process_raw(buf, False, True)
            else:
                break
        i=i+1
        decoder.end_utt()
    hypothesis = decoder.hyp()
    s=hypothesis.hypstr
    #print(s)
    z="".join(s.split())
    z=z.replace("$^"," ")
    z=z.replace("^"," ")
    z=z.replace("$"," ")
    z=z.replace("_","")
    z=z.strip()
    print (z)
    i=0
    DATADIR1="/home/tania/z1/kannada1-2"
    lm = NGramModel(config, decoder.get_logmath(), path.join(DATADIR1, 'etc/kannada1-2.lm.DMP'))
    
    decoder.set_lm('kannada1-2', lm)
    decoder.set_search('kannada1-2')
    
    decoder.load_dict("/home/tania/z1/kannada1-2/etc/kannada1-2.dic",None,None)
    while i<2:
        decoder.start_utt()
        stream = open(path.join(DATADIR, 'kan_0702.wav'), 'rb')
        while True:
                buf = stream.read()
                if buf:
                    decoder.process_raw(buf, False, True)
                else:
                    break
        i=i+1
        decoder.end_utt()
    hypothesis = decoder.hyp()
    s=hypothesis.hypstr
    print (s)
    

    In the above code i was able to set a new LM and load a new dict. How can i update the hmm model in the code from sylabble.cd_cont_200 to kannada1-2.cd_cont_200 without creating a new decoder object? Is it posibble?
    Without changing the HMM model its still able to give proper results I'm not sure how
    and the while loop i used the loop twice because in the first decoding i dont get the right result. i tried changing the changing the channel parameters too but i dont the right decoded sentence in first shot. Please help me out

     

    Last edit: Tania Mendonca 2017-04-17
    • Nickolay V. Shmyrev

      Not possible.

       
      • Tania Mendonca

        Tania Mendonca - 2017-04-17

        Any idea as to how its getting the right results for word decoding from the sylabble based HMM? Is it because the HMM is phone based though i have made a sylabble based?

         

        Last edit: Tania Mendonca 2017-04-17

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.