Esempio n. 1
0
    def loop(self):
        count = 0
        while True:
            i = self.sr.voice_detection()
            i = tokenize_weak.format(i)
            if (self.compare_sentence_to_list(i, self.words_start)
                    and count <= 0) or self.first_run:
                count = self.count_max
                print('starting')
                if not self.first_run:
                    self.voice.speech_out('yes')
                    i = ''
                self.first_run = False
            if self.compare_sentence_to_list(i, self.words_stop):
                count = 0
                print('stopping')
            i = self.check_sentence(i)
            if len(i) > 0:
                if count > 0:
                    out = self.model.get_sentence(i)

                    blacklisted = False
                    for jj in self.blacklist:
                        if out.startswith(jj):
                            blacklisted = True
                    if not blacklisted:
                        self.voice.speech_out(out)
            count -= 1
            if count <= 0:
                print('quiet')
Esempio n. 2
0
    def loop(self):
        global mode
        count = 0
        while True:
            self.pin_a_on()
            i = self.sr.voice_detection()
            self.pin_a_off()
            if not no_tokenize_weak: i = tokenize_weak.format(i)
            if (self.compare_sentence_to_list(i, self.words_start)
                    and count <= 0) or self.first_run:
                count = self.count_max
                print('starting')
                if not self.first_run:
                    self.voice.speech_out('yes')
                    i = ''
                self.first_run = False
            if self.compare_sentence_to_list(i, self.words_stop) and must_stop:
                count = 0
                print('stopping')
            i = self.check_sentence(i)
            if len(i) > 0:
                if count > 0:
                    if mode == 'signal': self.voice.beep_out()
                    ts = time.time()
                    out = self.model.get_sentence(i)
                    te = time.time()
                    if mode == 'signal': self.voice.beep_out()

                    ## seconds ##
                    self.time_total = (te - ts)
                    if self.time_total > self.time_allowed: mode = 'signal'
                    print(self.time_total, 'time')

                    blacklisted = False
                    for jj in self.blacklist:
                        if out.startswith(jj):
                            blacklisted = True
                    if not blacklisted:
                        print(out)
                        self.voice.speech_out(out)
            if not do_not_end: count -= 1
            if count <= 0:
                print('quiet')
    def loop(self):
        global mode
        count = 0
        num = 0
        print('starting')
        self.print_contents(pr=False, code='w')
        while True:
            #self.pin_a_on()
            #i = self.sr.voice_detection()
            if stat_limit <= num: break
            i = input(str(num)+ '> ')
            #print(i)
            #self.pin_a_off()
            if not no_tokenize_weak: i = tokenize_weak.format(i)
            if (self.compare_sentence_to_list(i, self.words_start) and count <= 0) or self.first_run:
                count = self.count_max

                if not self.first_run:
                    #self.voice.speech_out('yes')
                    i = ''
                self.first_run = False
            if self.compare_sentence_to_list(i, self.words_stop) and must_stop:
                count = 0
                #print('stopping')
            i = self.check_sentence(i)
            print(i)
            if len(i) > 0:
                if count > 0 :
                    #if mode == 'signal': self.voice.beep_out()
                    ts = time.time()
                    if (i.strip() == '' or len(i.strip()) == 0) or i.strip() == "'" :
                        i = '.'
                    out = self.model.get_sentence(i)
                    te = time.time()
                    #if mode == 'signal': self.voice.beep_out()
                    if out not in self.responses:
                        self.responses[out] = 1
                    else:
                        self.responses[out] += 1
                    for word in out.split():
                        if word not in self.responses_words:
                            self.responses_words[word] = 1
                        else:
                            self.responses_words[word] += 1
                        self.responses_words_list.append(word) ## do not use !!
                        pass
                    #print(' count:', self.responses[out])
                    ## seconds ##
                    self.time_total = (te - ts)
                    if self.time_total > self.time_allowed: mode = 'signal'
                    #print(self.time_total, 'time')

                    blacklisted = False
                    for jj in self.blacklist:
                        if out.startswith(jj):
                            blacklisted = True
                    if not blacklisted:
                        print('[',out, '] count:', self.responses[out])
                        self.responses_list.append([i, out])
                        #self.voice.speech_out(out)
            if not do_not_end: count -= 1
            num += 1
            if num % 100 == 0:
                self.print_contents(pr=False, code='a')
            if count <= 0 :
                #print('quiet')
                pass
    def loop(self):
        global mode
        count = 0
        self.num = 0
        print('starting')
        self.loop_pass_num += 1
        self.print_contents(pr=False, code='w')
        while True:  #for _ in range(max(stat_limit, stat_tab)):
            #self.pin_a_on()
            #i = self.sr.voice_detection()
            self.lines += 1
            if stat_tab <= self.num and not original_sentences: break
            i = input(str(self.num) + ' > ')
            #print(i)
            #self.pin_a_off()
            if not no_tokenize_weak: i = tokenize_weak.format(i)
            if (self.compare_sentence_to_list(i, self.words_start)
                    and count <= 0) or self.first_run:
                count = self.count_max

                if not self.first_run:
                    #self.voice.speech_out('yes')
                    i = ''
                self.first_run = False
            if self.compare_sentence_to_list(i, self.words_stop) and must_stop:
                count = 0
                #print('stopping')
            i = self.check_sentence(i)
            print(i)
            if len(i) > 0 or True:
                if count > 0 or True:
                    #if mode == 'signal': self.voice.beep_out()
                    ts = time.time()
                    if (i.strip() == ''
                            or len(i.strip()) == 0) or i.strip() == "'":
                        i = '.'
                    if original_sentences:
                        if i.strip() in self.original_input_sentences:
                            '''
                            if i == "":
                                self.num += 1 ## use or not use!!
                            if (num % interval == 0 and num <= stat_limit) or num == stat_limit:
                                self.print_contents(pr=False, code='a')
                            '''
                            #self.num += 1
                            continue
                        else:
                            if self.loop_pass_num == 1:
                                self.original_input_sentences.append(i.strip())

                    out = self.model.get_sentence(i)
                    te = time.time()
                    #if mode == 'signal': self.voice.beep_out()
                    if out not in self.responses:
                        self.responses[out] = 1
                    else:
                        self.responses[out] += 1
                    for word in out.split():
                        if word not in self.responses_words:
                            self.responses_words[word] = 1
                        else:
                            self.responses_words[word] += 1
                        self.responses_words_list.append(
                            word)  ## do not use !!
                        pass
                    #print(' count:', self.responses[out])
                    ## seconds ##
                    self.time_total = (te - ts)
                    if self.time_total > self.time_allowed: mode = 'signal'
                    #print(self.time_total, 'time')

                    blacklisted = False
                    for jj in self.blacklist:
                        if out.startswith(jj):
                            blacklisted = True
                    if not blacklisted:
                        print('[', out, '] count:', self.responses[out])
                        self.responses_list.append([i, out])
                        #self.voice.speech_out(out)
            if not do_not_end: count -= 1
            self.num += 1
            if (self.num % interval == 0
                    and self.num <= stat_limit) or self.num == stat_limit:
                self.print_contents(pr=False, code='a')
            if self.num >= stat_limit:
                break
            if count <= 0:
                #print('quiet')
                pass
        print()
        print(self.num, 'num total')
        print(self.lines, 'lines total scanned')