Exemple #1
0
def main():
    import autopath
    cfg = Config.load_configs(['resources/default-lz.cfg'],
                              use_default=False,
                              project_root=True)
    #cfg = {'DM': {'UfalRuleDM':
    # {'ontology':"/xdisk/devel/vystadial/alex/applications/" + \
    #             "CamInfoRest/ontology.cfg",
    #  'db_cfg': "/xdisk/devel/vystadial/alex/applications/" + \
    #            "CamInfoRest/cued_data/CIRdbase_V7_noloc.txt"}}}
    u = UfalRuleDM(cfg)
    # ufal_ds = u.create_ds()
    while 1:
        curr_acts = DialogueActNBList()
        for ln in sys.stdin:
            if len(ln.strip()) == 0:
                break
            ln = ln.strip()
            print ln
            score, act = ln.split(" ", 1)
            score = float(score)
            curr_acts.add(score, DialogueActItem(dai=act))

        u.da_in(curr_acts)
        print "  >", u.da_out()
Exemple #2
0
    def test_tecto_template_nlg(self):
        # initialize
        cfg = Config.load_configs(config=CONFIG_DICT,
                                  use_default=False,
                                  log=False)
        nlg = TectoTemplateNLG(cfg)
        # test all cases
        for da, correct_text in zip(DAS, TEXTS):
            # try generation
            da = DialogueAct(da)
            generated_text = nlg.generate(da)
            # print output
            s = []
            s.append("")
            s.append("Input DA:")
            s.append(unicode(da))
            s.append("")
            s.append("Correct text:")
            s.append(correct_text)
            s.append("")
            s.append("Generated text:")
            s.append(generated_text)
            s.append("")

            # test the result
            self.assertEqual(correct_text, generated_text)
Exemple #3
0
    def test_tecto_template_nlg(self):
        # initialize
        cfg = Config.load_configs(config=CONFIG_DICT, use_default=False,
                                  log=False)
        nlg = TectoTemplateNLG(cfg)
        # test all cases
        for da, correct_text in zip(DAS, TEXTS):
            # try generation
            da = DialogueAct(da)
            generated_text = nlg.generate(da)
            # print output
            s = []
            s.append("")
            s.append("Input DA:")
            s.append(unicode(da))
            s.append("")
            s.append("Correct text:")
            s.append(correct_text)
            s.append("")
            s.append("Generated text:")
            s.append(generated_text)
            s.append("")

            # test the result
            self.assertEqual(correct_text, generated_text)
Exemple #4
0
    def _get_cfg(self):
        cfg = Config(config={
            'PublicTransportInfoCS': {
                'max_turns': 120,
            },
            'DM': {
                'directions': {
                    'type': directions.GoogleDirectionsFinder,

                },
                'dialogue_policy': {
                    'PTICSHDCPolicy': {
                        'accept_prob': 0.5,
                        'accept_prob_being_requested': 0.5,
                        'accept_prob_being_confirmed': 0.5,
                        'accept_prob_ludait': 0.5,
                        'accept_prob_noninformed': 0.5,
                        'confirm_prob': 0.5,
                        'select_prob': 0.5,
                        'min_change_prob': 0.5
                    }
                },
                'dialogue_state': {
                    'type': DeterministicDiscriminativeDialogueState,
                 },
                'DeterministicDiscriminativeDialogueState': {
                    'type': 'UFAL_DSTC_1.0_approx',
                },
                'ontology': as_project_path('applications/PublicTransportInfoCS/data/ontology.py'),
            },
            'Logging': {
                'system_logger': alex.utils.DummyLogger(),
                'session_logger': alex.utils.DummyLogger()
            },
            'weather': {
                'dictionary': as_project_path('applications/PublicTransportInfoCS/weather_cs.cfg'),
                'suffix': 'CZ',
                'units': 'celsius',
            }
        })
        return cfg
Exemple #5
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
        AudioHub runs the spoken dialog system, using your microphone and speakers.

        The default configuration is loaded from '<app root>/resources/default.cfg'.

        Additional configuration parameters can be passed as an argument '-c'.
        Any additional config parameters overwrite their previous values.
      """)

    parser.add_argument('-c', "--configs", nargs="+",
                        help='additional configuration file')
    args = parser.parse_args()

    cfg = Config.load_configs(args.configs)

    cfg['Logging']['system_logger'].info("Voip Hub\n" + "=" * 120)

    vhub = AudioHub(cfg)
    vhub.run()
Exemple #6
0
def main():
    cfg = Config.load_configs(['resources/default-lz.cfg'],
                              use_default=False, project_root=True)
    #cfg = {'DM': {'UfalRuleDM':
    # {'ontology':"/xdisk/devel/vystadial/alex/applications/" + \
    #             "CamInfoRest/ontology.cfg",
    #  'db_cfg': "/xdisk/devel/vystadial/alex/applications/" + \
    #            "CamInfoRest/cued_data/CIRdbase_V7_noloc.txt"}}}
    u = UfalRuleDM(cfg)
    # ufal_ds = u.create_ds()
    while 1:
        curr_acts = DialogueActNBList()
        for ln in sys.stdin:
            if len(ln.strip()) == 0:
                break
            ln = ln.strip()
            print ln
            score, act = ln.split(" ", 1)
            score = float(score)
            curr_acts.add(score, DialogueActItem(dai=act))

        u.da_in(curr_acts)
        print "  >", u.da_out()
Exemple #7
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
        AudioHub runs the spoken dialog system, using your microphone and speakers.

        The default configuration is loaded from '<app root>/resources/default.cfg'.

        Additional configuration parameters can be passed as an argument '-c'.
        Any additional config parameters overwrite their previous values.
      """)

    parser.add_argument('-c',
                        "--configs",
                        nargs="+",
                        help='additional configuration file')
    args = parser.parse_args()

    cfg = Config.load_configs(args.configs)

    cfg['Logging']['system_logger'].info("Voip Hub\n" + "=" * 120)

    vhub = AudioHub(cfg)
    vhub.run()
    def test_session_logger(self):
        cfg = Config.load_configs(config=CONFIG_DICT, use_default=False)

        sl = SessionLogger()

        # test 3 calls at once
        for i in range(3):
            sess_dir = "./%d" % i
            if not os.path.isdir(sess_dir):
                os.mkdir(sess_dir)
            sl.session_start(sess_dir)
            sl.config('config = ' + unicode(cfg))
            sl.header(cfg['Logging']["system_name"], cfg['Logging']["version"])
            sl.input_source("voip")

            sl.dialogue_rec_start(None, "both_complete_dialogue.wav")
            sl.dialogue_rec_start("system", "system_complete_dialogue.wav")
            sl.dialogue_rec_start("user", "user_complete_dialogue.wav")
            sl.dialogue_rec_end("both_complete_dialogue.wav")
            sl.dialogue_rec_end("system_complete_dialogue.wav")
            sl.dialogue_rec_end("user_complete_dialogue.wav")

            sl.turn("system")
            sl.dialogue_act("system", "hello()")
            sl.text("system", "Hello.")
            sl.rec_start("system", "system1.wav")
            sl.rec_end("system1.wav")

            sl.turn("user")
            sl.rec_start("user", "user1.wav")
            sl.rec_end("user1.wav")

            A1, A2, A3 = 0.90, 0.05, 0.05
            B1, B2, B3 = 0.70, 0.20, 0.10
            C1, C2, C3 = 0.80, 0.10, 0.10

            asr_confnet = UtteranceConfusionNetwork()
            asr_confnet.add([[A1, "want"], [A2, "has"], [A3, 'ehm']])
            asr_confnet.add([[B1, "Chinese"], [B2, "English"], [B3, 'cheap']])
            asr_confnet.add([[C1, "restaurant"], [C2, "pub"], [C3, 'hotel']])
            asr_confnet.merge()
            asr_confnet.normalise()
            asr_confnet.sort()

            asr_nblist = asr_confnet.get_utterance_nblist()

            sl.asr("user", "user1.wav", asr_nblist, asr_confnet)

            slu_confnet = DialogueActConfusionNetwork()
            slu_confnet.add(0.7, DialogueActItem('hello'))
            slu_confnet.add(0.6, DialogueActItem('thankyou'))
            slu_confnet.add(0.4, DialogueActItem('restart'))
            slu_confnet.add(0.1, DialogueActItem('bye'))
            slu_confnet.merge()
            slu_confnet.normalise()
            slu_confnet.sort()

            slu_nblist = slu_confnet.get_da_nblist()

            sl.slu("user", "user1.wav", slu_nblist, slu_confnet)

            sl.turn("system")
            sl.dialogue_act("system", "thankyou()")
            sl.text("system", "Thank you.", cost=1.0)
            sl.rec_start("system", "system2.wav")
            sl.rec_end("system2.wav")
            sl.barge_in("system", tts_time=True)

            sl.turn("user")
            sl.rec_start("user", "user2.wav")
            sl.rec_end("user2.wav")
            sl.hangup("user")
Exemple #9
0
def main():
    from alex.utils.config import Config
    from alex.utils.caminfodb import CamInfoDb

    # This implicitly loads also the default config.
    cfg = Config.load_configs(['resources/lz.cfg'], project_root=True)

    db_cfg = cfg['DM']["PUfalRuleDM"]['db_cfg']  # database provider
    db = CamInfoDb(db_cfg)

    pdm = PRuleDM(cfg, db)
    pdm.new_dialogue()
    pdm.da_out()

    # user's input
    cn = DialogueActConfusionNetwork()
    cn.add(0.7, DialogueActItem(dai="inform(food=chinese)"))
    cn.add(0.2, DialogueActItem(dai="inform(food=indian)"))
    cn.add(0.5, DialogueActItem(dai="inform(food=chinese)"))
    cn.add(0.1, DialogueActItem(dai="inform(food=czech)"))
    cn.add(0.1, DialogueActItem(dai="confirm(food=czech)"))
    cn.add(0.6, DialogueActItem(dai="request(phone)"))
    cn.add(0.3, DialogueActItem(dai="reset()"))
    cn.add(0.3, DialogueActItem(dai="asdf()"))
    cn.add(0.3, DialogueActItem(dai="reset()"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.99, DialogueActItem(dai="confirm(food=indian)"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.77, DialogueActItem(dai="reqalts()"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.77, DialogueActItem(dai="reqalts()"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.99, DialogueActItem(dai="confirm(food=indian)"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.99, DialogueActItem(dai="request(name)"))
    cn.add(0.99, DialogueActItem(dai="request(food)"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()

    cn = DialogueActConfusionNetwork()
    cn.add(0.99, DialogueActItem(dai="bye()"))
    print cn
    pdm.da_in(cn)
    pdm.da_out()
Exemple #10
0
def get_config():
    global cfg
    cfg = Config.load_configs(['../demos/ptien/simulator.cfg', '../demos/ptien/ptien_metadata.py'], log=False)
Exemple #11
0
    parser_b.add_argument(
        'reference',
        help=
        'Key value file: Keys contain paths to wav files. Values are reference transcriptions.'
    )

    args = parser.parse_args()

    if os.path.exists(args.out_dir):
        if not args.f:
            print "\nThe directory '%s' already exists!\n" % args.out_dir
            parser.print_usage()
            parser.exit()
    else:
        # create the dir
        try:
            os.makedirs(args.out_dir)
        except OSError as exc:
            if exc.errno != errno.EEXIST or os.path.isdir(args.out_dir):
                raise exc

    cfg = Config.load_configs(args.configs, use_default=True)
    asr = asr_factory(cfg)

    if args.command == 'extract':
        extract_from_xml(args.indomain_data_dir, args.out_dir, cfg)
    elif args.command == 'load':
        decode_with_reference(args.reference, args.out_dir, args.num_workers)
    else:
        raise Exception('Argparse mechanism failed: Should never happen')
                     'as confnets.'))
    arger.add_argument('dirname',
                       help='directory name where to search for WAVs;  in '
                            'fact, it can be path towards a file listing '
                            'paths to the files in question or path globs or '
                            'paths to their immediate parent directories')
    arger.add_argument('outfname', help='path towards the output file')
    arger.add_argument('-c', '--configs', nargs='+',
                       help='configuration files',
                       required=True)
    arger.add_argument('-s', '--skip', type=int,
                       help="how many wavs to skip")
    arger.add_argument('-g', '--ignore',
                       type=argparse.FileType('r'),
                       metavar='FILE',
                       help='Path towards a file listing globs of CUED '
                            'call log files that should be ignored.\n'
                            'The globs are interpreted wrt. the current '
                            'working directory. For an example, see the '
                            'source code.')
    args = arger.parse_args()

    cfg = Config.load_configs(args.configs, log=False)

    try:
        DEBUG = cfg['General']['debug']
    except KeyError:
        pass

    main(args.dirname, args.outfname, cfg, args.skip, args.ignore)
Exemple #13
0
 def setUp(self):
     cfg = Config.load_configs()
     cfg.config['ASR']['Julius']['msg_timeout'] = 5.
     cfg.config['ASR']['Julius']['timeout'] = 5.
     cfg.config['corpustools']['get_jasr_confnets']['rt_ratio'] = 0.
     self.cfg = cfg
Exemple #14
0
def get_config():
    global cfg
    cfg = Config.load_configs(['../applications/PublicTransportInfoEN/ptien.cfg'])#, '../applications/PublicTransportInfoEN/ptien_hdc_slu.cfg'])
    cfg['Logging']['system_logger'].info("Voip Hub\n" + "=" * 120)
Exemple #15
0
    print

    text = 'Hello. Thank you for calling. '
    voice = 'kal'

    print "Synthesize text:", text
    print "Voice:          ", voice
    print

    c = {
        'TTS': {
            'Flite': {
                'debug': False,
                'voice': 'kal'
            }
        }
    }
    cfg = Config.load_configs(log=False)
    cfg.update(c)

    tts = FliteTTS(cfg)

    print 'calling TTS'
    wav = tts.synthesize(text)

    print 'saving the TTS audio in ./tmp/flite_tts.wav'
    audio.save_wav(cfg, './tmp/flite_tts.wav', wav)

    print 'playing audio'
    audio.play(cfg, wav)
def get_config():
    global config
    config = Config.load_configs(['config_gp_sarsa.py'], log=False)
Exemple #17
0
        ('../resources/private/mturk.cfg') and any additional config files passed as
        an argument of a '-c'. The additional config file overwrites any
        default or previous values.

        Remember that the "private" directory is not distributed and it contains
        mainly information that you do not want to share.
      """)

    parser.add_argument('-c',
                        "--configs",
                        nargs='+',
                        help='additional configuration files')
    args = parser.parse_args()

    mturk_cfg_fname = as_project_path('resources/private/mturk.cfg')
    cfg = Config.load_configs([mturk_cfg_fname] + args.configs, log=False)

    print "Expire all HITs"

    conn = MTurkConnection(
        aws_access_key_id=cfg['MTURK']['aws_access_key_id'],
        aws_secret_access_key=cfg['MTURK']['aws_secret_access_key'],
        host=cfg['MTURK']['host'])

    for pnum in range(1, 50):
        for hit in conn.search_hits(page_size=100, page_number=pnum):
            print "HITId:", hit.HITId

            hitStatus = defaultdict(int)
            for ass in conn.get_assignments(hit.HITId,
                                            status='Submitted',
Exemple #18
0
                       help='directory name where to search for WAVs;  in '
                       'fact, it can be path towards a file listing '
                       'paths to the files in question or path globs or '
                       'paths to their immediate parent directories')
    arger.add_argument('outfname', help='path towards the output file')
    arger.add_argument('-c',
                       '--configs',
                       nargs='+',
                       help='configuration files',
                       required=True)
    arger.add_argument('-s', '--skip', type=int, help="how many wavs to skip")
    arger.add_argument('-g',
                       '--ignore',
                       type=argparse.FileType('r'),
                       metavar='FILE',
                       help='Path towards a file listing globs of CUED '
                       'call log files that should be ignored.\n'
                       'The globs are interpreted wrt. the current '
                       'working directory. For an example, see the '
                       'source code.')
    args = arger.parse_args()

    cfg = Config.load_configs(args.configs, log=False)

    try:
        DEBUG = cfg['General']['debug']
    except KeyError:
        pass

    main(args.dirname, args.outfname, cfg, args.skip, args.ignore)
Exemple #19
0
 def setUp(self):
     cfg = Config.load_configs()
     cfg.config['ASR']['Julius']['msg_timeout'] = 5.
     cfg.config['ASR']['Julius']['timeout'] = 5.
     cfg.config['corpustools']['get_jasr_confnets']['rt_ratio'] = 0.
     self.cfg = cfg
Exemple #20
0
def get_config():
    global cfg
    cfg = Config.load_configs(['scheduler_simulator.cfg'], log=False)
Exemple #21
0
def main():
    cldb = CategoryLabelDatabase('../data/database.py')
    preprocessing = PTIENSLUPreprocessing(cldb)
    slu = PTIENHDCSLU(preprocessing, cfg={'SLU': {PTIENHDCSLU: {'utt2da': as_project_path("applications/PublicTransportInfoEN/data/utt2da_dict.txt")}}})
    cfg = Config.load_configs(['../kaldi.cfg',], use_default=True)
    asr_rec = asr_factory(cfg)                    

    fn_uniq_trn = 'uniq.trn'
    fn_uniq_trn_hdc_sem = 'uniq.trn.hdc.sem'
    fn_uniq_trn_sem = 'uniq.trn.sem'

    fn_all_sem = 'all.sem'
    fn_all_trn = 'all.trn'
    fn_all_trn_hdc_sem = 'all.trn.hdc.sem'
    fn_all_asr = 'all.asr'
    fn_all_asr_hdc_sem = 'all.asr.hdc.sem'
    fn_all_nbl = 'all.nbl'
    fn_all_nbl_hdc_sem = 'all.nbl.hdc.sem'

    fn_train_sem = 'train.sem'
    fn_train_trn = 'train.trn'
    fn_train_trn_hdc_sem = 'train.trn.hdc.sem'
    fn_train_asr = 'train.asr'
    fn_train_asr_hdc_sem = 'train.asr.hdc.sem'
    fn_train_nbl = 'train.nbl'
    fn_train_nbl_hdc_sem = 'train.nbl.hdc.sem'

    fn_dev_sem = 'dev.sem'
    fn_dev_trn = 'dev.trn'
    fn_dev_trn_hdc_sem = 'dev.trn.hdc.sem'
    fn_dev_asr = 'dev.asr'
    fn_dev_asr_hdc_sem = 'dev.asr.hdc.sem'
    fn_dev_nbl = 'dev.nbl'
    fn_dev_nbl_hdc_sem = 'dev.nbl.hdc.sem'

    fn_test_sem = 'test.sem'
    fn_test_trn = 'test.trn'
    fn_test_trn_hdc_sem = 'test.trn.hdc.sem'
    fn_test_asr = 'test.asr'
    fn_test_asr_hdc_sem = 'test.asr.hdc.sem'
    fn_test_nbl = 'test.nbl'
    fn_test_nbl_hdc_sem = 'test.nbl.hdc.sem'

    indomain_data_dir = "indomain_data"

    print "Generating the SLU train and test data"
    print "-"*120
    ###############################################################################################

    files = []
    files.append(glob.glob(os.path.join(indomain_data_dir, 'asr_transcribed.xml')))
    files.append(glob.glob(os.path.join(indomain_data_dir, '*', 'asr_transcribed.xml')))
    files.append(glob.glob(os.path.join(indomain_data_dir, '*', '*', 'asr_transcribed.xml')))
    files.append(glob.glob(os.path.join(indomain_data_dir, '*', '*', '*', 'asr_transcribed.xml')))
    files.append(glob.glob(os.path.join(indomain_data_dir, '*', '*', '*', '*', 'asr_transcribed.xml')))
    files.append(glob.glob(os.path.join(indomain_data_dir, '*', '*', '*', '*', '*', 'asr_transcribed.xml')))
    files = various.flatten(files)

    sem = []
    trn = []
    trn_hdc_sem = []
    asr = []
    asr_hdc_sem = []
    nbl = []
    nbl_hdc_sem = []

    for fn in files[:100000]:
        f_dir = os.path.dirname(fn)

        print "Processing:", fn
        doc = xml.dom.minidom.parse(fn)
        turns = doc.getElementsByTagName("turn")

        for i, turn in enumerate(turns):
            if turn.getAttribute('speaker') != 'user':
                continue

            recs = turn.getElementsByTagName("rec")
            trans = turn.getElementsByTagName("asr_transcription")
            asrs = turn.getElementsByTagName("asr")

            if len(recs) != 1:
                print "Skipping a turn {turn} in file: {fn} - recs: {recs}".format(turn=i,fn=fn, recs=len(recs))
                continue

            if len(asrs) == 0 and (i + 1) < len(turns):
                next_asrs = turns[i+1].getElementsByTagName("asr")
                if len(next_asrs) != 2:
                    print "Skipping a turn {turn} in file: {fn} - asrs: {asrs} - next_asrs: {next_asrs}".format(turn=i, fn=fn, asrs=len(asrs), next_asrs=len(next_asrs))
                    continue
                print "Recovered from missing ASR output by using a delayed ASR output from the following turn of turn {turn}. File: {fn} - next_asrs: {asrs}".format(turn=i, fn=fn, asrs=len(next_asrs))
                hyps = next_asrs[0].getElementsByTagName("hypothesis")
            elif len(asrs) == 1:
                hyps = asrs[0].getElementsByTagName("hypothesis")
            elif len(asrs) == 2:
                print "Recovered from EXTRA ASR outputs by using a the last ASR output from the turn. File: {fn} - asrs: {asrs}".format(fn=fn, asrs=len(asrs))
                hyps = asrs[-1].getElementsByTagName("hypothesis")
            else:
                print "Skipping a turn {turn} in file {fn} - asrs: {asrs}".format(turn=i,fn=fn, asrs=len(asrs))
                continue

            if len(trans) == 0:
                print "Skipping a turn in {fn} - trans: {trans}".format(fn=fn, trans=len(trans))
                continue

            wav_key = recs[0].getAttribute('fname')
            wav_path = os.path.join(f_dir, wav_key)
            
            # FIXME: Check whether the last transcription is really the best! FJ
            t = various.get_text_from_xml_node(trans[-1])
            t = normalise_text(t)

            
            if '--asr-log' not in sys.argv:
                asr_rec_nbl = asr_rec.rec_wav_file(wav_path)
                a = unicode(asr_rec_nbl.get_best())
            else:  
                a = various.get_text_from_xml_node(hyps[0])
                a = normalise_semi_words(a)

            if exclude_slu(t) or 'DOM Element:' in a:
                print "Skipping transcription:", unicode(t)
                print "Skipping ASR output:   ", unicode(a)
                continue

            # The silence does not have a label in the language model.
            t = t.replace('_SIL_','')

            trn.append((wav_key, t))

            print "Parsing transcription:", unicode(t)
            print "                  ASR:", unicode(a)

            # HDC SLU on transcription
            s = slu.parse_1_best({'utt':Utterance(t)}).get_best_da()
            trn_hdc_sem.append((wav_key, s))

            if '--uniq' not in sys.argv:
                # HDC SLU on 1 best ASR
                if '--asr-log' not in sys.argv:
                    a = unicode(asr_rec_nbl.get_best())
                else:  
                    a = various.get_text_from_xml_node(hyps[0])
                    a = normalise_semi_words(a)

                asr.append((wav_key, a))

                s = slu.parse_1_best({'utt':Utterance(a)}).get_best_da()
                asr_hdc_sem.append((wav_key, s))

                # HDC SLU on N best ASR
                n = UtteranceNBList()
                if '--asr-log' not in sys.argv:
                   n = asr_rec_nbl
                   
                   print 'ASR RECOGNITION NBLIST\n',unicode(n)
                else:
                    for h in hyps:
                        txt = various.get_text_from_xml_node(h)
                        txt = normalise_semi_words(txt)

                        n.add(abs(float(h.getAttribute('p'))),Utterance(txt))

                n.merge()
                n.normalise()

                nbl.append((wav_key, n.serialise()))

                if '--fast' not in sys.argv:
                    s = slu.parse_nblist({'utt_nbl':n}).get_best_da()
                nbl_hdc_sem.append((wav_key, s))

            # there is no manual semantics in the transcriptions yet
            sem.append((wav_key, None))


    uniq_trn = {}
    uniq_trn_hdc_sem = {}
    uniq_trn_sem = {}
    trn_set = set()

    sem = dict(trn_hdc_sem)
    for k, v in trn:
        if not v in trn_set:
            trn_set.add(v)
            uniq_trn[k] = v
            uniq_trn_hdc_sem[k] = sem[k]
            uniq_trn_sem[k] = v + " <=> " + unicode(sem[k])

    save_wavaskey(fn_uniq_trn, uniq_trn)
    save_wavaskey(fn_uniq_trn_hdc_sem, uniq_trn_hdc_sem, trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
    save_wavaskey(fn_uniq_trn_sem, uniq_trn_sem)

    # all
    save_wavaskey(fn_all_trn, dict(trn))
    save_wavaskey(fn_all_trn_hdc_sem, dict(trn_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))

    if '--uniq' not in sys.argv:
        save_wavaskey(fn_all_asr, dict(asr))
        save_wavaskey(fn_all_asr_hdc_sem, dict(asr_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))

        save_wavaskey(fn_all_nbl, dict(nbl))
        save_wavaskey(fn_all_nbl_hdc_sem, dict(nbl_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))


        seed_value = 10

        random.seed(seed_value)
        random.shuffle(trn)
        random.seed(seed_value)
        random.shuffle(trn_hdc_sem)
        random.seed(seed_value)
        random.shuffle(asr)
        random.seed(seed_value)
        random.shuffle(asr_hdc_sem)
        random.seed(seed_value)
        random.shuffle(nbl)
        random.seed(seed_value)
        random.shuffle(nbl_hdc_sem)

        # trn
        train_trn = trn[:int(0.8*len(trn))]
        dev_trn = trn[int(0.8*len(trn)):int(0.9*len(trn))]
        test_trn = trn[int(0.9*len(trn)):]

        save_wavaskey(fn_train_trn, dict(train_trn))
        save_wavaskey(fn_dev_trn, dict(dev_trn))
        save_wavaskey(fn_test_trn, dict(test_trn))

        # trn_hdc_sem
        train_trn_hdc_sem = trn_hdc_sem[:int(0.8*len(trn_hdc_sem))]
        dev_trn_hdc_sem = trn_hdc_sem[int(0.8*len(trn_hdc_sem)):int(0.9*len(trn_hdc_sem))]
        test_trn_hdc_sem = trn_hdc_sem[int(0.9*len(trn_hdc_sem)):]

        save_wavaskey(fn_train_trn_hdc_sem, dict(train_trn_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_dev_trn_hdc_sem, dict(dev_trn_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_test_trn_hdc_sem, dict(test_trn_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))

        # asr
        train_asr = asr[:int(0.8*len(asr))]
        dev_asr = asr[int(0.8*len(asr)):int(0.9*len(asr))]
        test_asr = asr[int(0.9*len(asr)):]

        save_wavaskey(fn_train_asr, dict(train_asr))
        save_wavaskey(fn_dev_asr, dict(dev_asr))
        save_wavaskey(fn_test_asr, dict(test_asr))

        # asr_hdc_sem
        train_asr_hdc_sem = asr_hdc_sem[:int(0.8*len(asr_hdc_sem))]
        dev_asr_hdc_sem = asr_hdc_sem[int(0.8*len(asr_hdc_sem)):int(0.9*len(asr_hdc_sem))]
        test_asr_hdc_sem = asr_hdc_sem[int(0.9*len(asr_hdc_sem)):]

        save_wavaskey(fn_train_asr_hdc_sem, dict(train_asr_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_dev_asr_hdc_sem, dict(dev_asr_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_test_asr_hdc_sem, dict(test_asr_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))

        # n-best lists
        train_nbl = nbl[:int(0.8*len(nbl))]
        dev_nbl = nbl[int(0.8*len(nbl)):int(0.9*len(nbl))]
        test_nbl = nbl[int(0.9*len(nbl)):]

        save_wavaskey(fn_train_nbl, dict(train_nbl))
        save_wavaskey(fn_dev_nbl, dict(dev_nbl))
        save_wavaskey(fn_test_nbl, dict(test_nbl))

        # nbl_hdc_sem
        train_nbl_hdc_sem = nbl_hdc_sem[:int(0.8*len(nbl_hdc_sem))]
        dev_nbl_hdc_sem = nbl_hdc_sem[int(0.8*len(nbl_hdc_sem)):int(0.9*len(nbl_hdc_sem))]
        test_nbl_hdc_sem = nbl_hdc_sem[int(0.9*len(nbl_hdc_sem)):]

        save_wavaskey(fn_train_nbl_hdc_sem, dict(train_nbl_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_dev_nbl_hdc_sem, dict(dev_nbl_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
        save_wavaskey(fn_test_nbl_hdc_sem, dict(test_nbl_hdc_sem), trans = lambda da: '&'.join(sorted(unicode(da).split('&'))))
Exemple #22
0
cldb = CategoryLabelDatabase('../data/database.py')
preprocessing = PTICSSLUPreprocessing(cldb)
slu = PTICSHDCSLU(
    preprocessing,
    cfg={
        'SLU': {
            PTICSHDCSLU: {
                'utt2da':
                as_project_path(
                    "applications/PublicTransportInfoCS/data/utt2da_dict.txt")
            }
        }
    })
cfg = Config.load_configs([
    '../kaldi.cfg',
], use_default=True)
asr_rec = asr_factory(cfg)


def normalise_semi_words(txt):
    # normalise these semi-words
    if txt == '__other__':
        txt = '_other_'
    elif txt == '__silence__':
        txt = '_other_'
    elif not txt:
        txt = '_other_'

    return txt
Exemple #23
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
        Switchboard system records conversation between two users.
        When the first user calls the system, the systems rejects the call. Then in a few seconds,
        it calls back to the first user, informs about how to use the system and the recording data.
        Then, it asks the first user to enter a phone number of a second user. If the number is entered successfully,
        it calls the second user.

        The systems calls back to the user to prevent any call charges on the users' side.

        The program reads the default config in the resources directory ('../resources/default.cfg').

        In addition, it reads all config file passed as an argument of a '-c'.
        The additional config files overwrites any default or previous values.

      """)

    parser.add_argument('-o', action="store", dest="caller", nargs='+', help='additional configure file')
    parser.add_argument('-d', action="store", dest="callee", nargs='+', help='additional configure file')
    args = parser.parse_args()

    cfg1 = Config.load_configs(args.caller)
    cfg2 = Config.load_configs(args.callee)

    run(cfg1, cfg2)


Exemple #24
0
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
        Gets account balance at MTURK.

        The program reads the default config in the resources directory
        ('../resources/private/mturk.cfg') and any additional config files passed as
        an argument of a '-c'. The additional config file overwrites any
        default or previous values.

        Remember that the "private" directory is not distributed and it contains
        mainly information that you do not want to share.
      """)

    parser.add_argument('-c', "--configs", nargs='+',
                        help='additional configuration files')
    args = parser.parse_args()

    mturk_cfg_fname = as_project_path('resources/private/mturk.cfg')
    cfg = Config.load_configs([mturk_cfg_fname] + args.configs, log=False)

    print "Gets MTURK account balance"
    print "-" * 120
    print

    conn = MTurkConnection(aws_access_key_id = cfg['MTURK']['aws_access_key_id'],
                           aws_secret_access_key = cfg['MTURK']['aws_secret_access_key'],
                           host = cfg['MTURK']['host'])

    print "Account balance:", conn.get_account_balance()
Exemple #25
0
    def test_session_logger(self):
        cfg = Config.load_configs(config=CONFIG_DICT, use_default=False)

        sl = SessionLogger()

        # test 3 calls at once
        for i in range(3):
            sess_dir = "./%d" % i
            if not os.path.isdir(sess_dir):
                os.mkdir(sess_dir)
            sl.session_start(sess_dir)
            sl.config('config = ' + unicode(cfg))
            sl.header(cfg['Logging']["system_name"], cfg['Logging']["version"])
            sl.input_source("voip")

            sl.dialogue_rec_start(None, "both_complete_dialogue.wav")
            sl.dialogue_rec_start("system", "system_complete_dialogue.wav")
            sl.dialogue_rec_start("user", "user_complete_dialogue.wav")
            sl.dialogue_rec_end("both_complete_dialogue.wav")
            sl.dialogue_rec_end("system_complete_dialogue.wav")
            sl.dialogue_rec_end("user_complete_dialogue.wav")

            sl.turn("system")
            sl.dialogue_act("system", "hello()")
            sl.text("system", "Hello.")
            sl.rec_start("system", "system1.wav")
            sl.rec_end("system1.wav")

            sl.turn("user")
            sl.rec_start("user", "user1.wav")
            sl.rec_end("user1.wav")

            A1, A2, A3 = 0.90, 0.05, 0.05
            B1, B2, B3 = 0.70, 0.20, 0.10
            C1, C2, C3 = 0.80, 0.10, 0.10

            asr_confnet = UtteranceConfusionNetwork()
            asr_confnet.add([[A1, "want"], [A2, "has"], [A3, 'ehm']])
            asr_confnet.add([[B1, "Chinese"],  [B2, "English"], [B3, 'cheap']])
            asr_confnet.add([[C1, "restaurant"],  [C2, "pub"],   [C3, 'hotel']])
            asr_confnet.merge()
            asr_confnet.normalise()
            asr_confnet.sort()

            asr_nblist = asr_confnet.get_utterance_nblist()

            sl.asr("user", "user1.wav", asr_nblist, asr_confnet)

            slu_confnet = DialogueActConfusionNetwork()
            slu_confnet.add(0.7, DialogueActItem('hello'))
            slu_confnet.add(0.6, DialogueActItem('thankyou'))
            slu_confnet.add(0.4, DialogueActItem('restart'))
            slu_confnet.add(0.1, DialogueActItem('bye'))
            slu_confnet.merge()
            slu_confnet.normalise()
            slu_confnet.sort()

            slu_nblist = slu_confnet.get_da_nblist()

            sl.slu("user", "user1.wav", slu_nblist, slu_confnet)

            sl.turn("system")
            sl.dialogue_act("system", "thankyou()")
            sl.text("system", "Thank you.", cost = 1.0)
            sl.rec_start("system", "system2.wav")
            sl.rec_end("system2.wav")
            sl.barge_in("system", tts_time = True)

            sl.turn("user")
            sl.rec_start("user", "user2.wav")
            sl.rec_end("user2.wav")
            sl.hangup("user")
Exemple #26
0
        test_vio.py tests the VoipIO component.

        The program reads the default config in the resources directory
        ('../resources/default.cfg') and any additional config files passed as
        an argument of a '-c'. The additional config file overwrites any
        default or previous values.

      """)

    parser.add_argument('-c',
                        "--configs",
                        nargs='+',
                        help='additional configuration files')
    args = parser.parse_args()

    cfg = Config.load_configs(args.configs)

    session_logger = cfg['Logging']['session_logger']
    system_logger = cfg['Logging']['system_logger']

    #########################################################################
    #########################################################################
    system_logger.info("Test of the VoipIO component\n" + "=" * 120)

    vio_commands, vio_child_commands = multiprocessing.Pipe()
    # used to send commands to VoipIO

    vio_record, vio_child_record = multiprocessing.Pipe()
    # I read from this connection recorded audio

    vio_play, vio_child_play = multiprocessing.Pipe()
Exemple #27
0
 def setUp(self):
     self.cfg = Config.load_configs(config=CONFIG_DICT, use_default=False,
                                    log=False)
Exemple #28
0
 def setUp(self):
     self.cfg = Config.load_configs(config=CONFIG_DICT,
                                    use_default=False,
                                    log=False)
Exemple #29
0
def get_config():
    global cfg
    cfg = Config.load_configs(['config_asr_simulator.py'], log=False)
Exemple #30
0
    print "Language:       ", language
    print

    c = {
        'TTS': {
            'Google': {
                'debug':
                False,
                'preprocessing':
                as_project_path("resources/tts/prep_speechtech_en.cfg"),
                'tempo':
                1.0,
                'language':
                language
            }
        }
    }
    cfg = Config.load_configs(log=False)
    cfg.update(c)

    tts = GoogleTTS(cfg)

    print 'calling TTS'
    wav = tts.synthesize(text)

    print 'saving the TTS audio in ./tmp/google_tts.wav'
    audio.save_wav(cfg, './tmp/google_tts.wav', wav)

    print 'playing audio'
    audio.play(cfg, wav)
Exemple #31
0
    parser_a.add_argument('indomain_data_dir',
                          help='Directory which should contain symlinks or directories with transcribed ASR')
    parser_b = subparsers.add_parser(
        'load', help='Load wav transcriptions and reference with full paths to wavs')
    parser_b.add_argument(
        'reference', help='Key value file: Keys contain paths to wav files. Values are reference transcriptions.')

    args = parser.parse_args()

    if os.path.exists(args.out_dir):
        if not args.f:
            print "\nThe directory '%s' already exists!\n" % args.out_dir
            parser.print_usage()
            parser.exit()
    else:
        # create the dir
        try:
            os.makedirs(args.out_dir)
        except OSError as exc:
            if exc.errno != errno.EEXIST or os.path.isdir(args.out_dir):
                raise exc

    cfg = Config.load_configs(args.configs, use_default=True)

    if args.command == 'extract':
        extract_from_xml(args.indomain_data_dir, args.out_dir, cfg)
    elif args.command == 'load':
        decode_with_reference(args.reference, args.out_dir, cfg)
    else:
        raise Exception('Argparse mechanism failed: Should never happen')
Exemple #32
0
        formatter_class=argparse.RawDescriptionHelpFormatter,
        description="""
        test_vio.py tests the VoipIO component.

        The program reads the default config in the resources directory
        ('../resources/default.cfg') and any additional config files passed as
        an argument of a '-c'. The additional config file overwrites any
        default or previous values.

      """)

    parser.add_argument('-c', "--configs", nargs='+',
                        help='additional configuration files')
    args = parser.parse_args()

    cfg = Config.load_configs(args.configs)

    session_logger = cfg['Logging']['session_logger']
    system_logger = cfg['Logging']['system_logger']

    #########################################################################
    #########################################################################
    system_logger.info("Test of the AudioIO component\n" + "=" * 120)

    wav = audio.load_wav(cfg, './resources/test16k-mono.wav')
    # split audio into frames
    wav = various.split_to_bins(wav, 2 * cfg['Audio']['samples_per_frame'])
    # remove the last frame

    aio_commands, aio_child_commands = multiprocessing.Pipe()  # used to send aio_commands
    audio_record, child_audio_record = multiprocessing.Pipe()  # I read from this connection recorded audio
Exemple #33
0
""" The script has commands:

--asr-log   it uses the asr hypotheses from call logs

"""

asr_log = 0
num_workers = 1



cldb = CategoryLabelDatabase('../data/database.py')
preprocessing = PTICSSLUPreprocessing(cldb)
slu = PTICSHDCSLU(preprocessing, cfg = {'SLU': {PTICSHDCSLU: {'utt2da': as_project_path("applications/PublicTransportInfoCS/data/utt2da_dict.txt")}}})
cfg = Config.load_configs(['../kaldi.cfg',], use_default=True)
asr_rec = asr_factory(cfg)

def normalise_semi_words(txt):
    # normalise these semi-words
    if txt == '__other__':
        txt = '_other_'
    elif txt == '__silence__':
        txt = '_other_'
    elif not txt:
        txt = '_other_'

    return txt

def process_call_log(fn):
    name = multiprocessing.current_process().name