Beispiel #1
0
class Clara():
    def __init__(self):
        #threading.Thread.__init__(self)
        self.config = yaml.safe_load(open("clara.yml"))
        self.speech_thread = SpeechToText(self.config, self.ready,
                                          self.thinking,
                                          self.recognize_success,
                                          self.recognize_failed)
        self.speech_thread.start()
        self.ui = UI()
        self.ui.set_version("clara.2018.001")
        self.ui.register_quit_function(self.exit)
        self.ui.register_mic_function(self.toggle_microphone)
        self.ui.run()

    def exit(self):
        sys.exit()

    def set_conversation(self, text):
        self.conversation_state = "conversation"
        self.voice = text
        self.ui.set_conversation(text)

    def set_error_conversation(self, text):
        self.conversation_state = "error"
        self.voice = text
        self.ui.set_conversation(text)
        Clock.schedule_once(self.clear_error, 2)

    def clear_error(self, dt):
        if self.conversation_state == "error":
            self.ready()

    def initialising(self):
        self.set_conversation("Initialising...")

    def ready(self):
        self.set_conversation("How can I help?")
        self.say("How can I help?")

    def thinking(self):
        self.ui.set_thinking(True)
        self.set_conversation("Thinking...")

    def recognize_success(self, text):
        self.ui.set_thinking(False)
        self.set_conversation("I heard " + text)

    def recognize_failed(self, error):
        self.ui.set_thinking(False)
        self.set_error_conversation("I failed to recognise what you said")

    def toggle_microphone(self):
        pass

    def say(self, text):
        t = TextToSpeech(self.config, text)
        t.start()
Beispiel #2
0
 def __init__(self):
     #threading.Thread.__init__(self)
     self.config = yaml.safe_load(open("clara.yml"))
     self.speech_thread = SpeechToText(self.config, self.ready,
                                       self.thinking,
                                       self.recognize_success,
                                       self.recognize_failed)
     self.speech_thread.start()
     self.ui = UI()
     self.ui.set_version("clara.2018.001")
     self.ui.register_quit_function(self.exit)
     self.ui.register_mic_function(self.toggle_microphone)
     self.ui.run()
Beispiel #3
0
class Speech:
    def __init__(self):
        self.speech_to_text = SpeechToText()
        self.current_speech = None

    # create thread for capturing speech
    def start(self):
        Thread(target=self._update_speech, args=()).start()

    def _update_speech(self):
        while (True):
            self.current_speech = self.speech_to_text.convert()

    # get the current speech
    def get_current_speech(self):
        return self.current_speech
Beispiel #4
0
class Speech:
 
    def __init__(self):
        self.speech_to_text = SpeechToText()
        self.current_speech = None

    # create thread for capturing speech
    def start(self):
        Thread(target=self._update_speech, args=()).start()
 
    def _update_speech(self):
        while(True):
            self.current_speech = self.speech_to_text.convert()
                 
    # get the current speech
    def get_current_speech(self):
        return self.current_speech
Beispiel #5
0
from speechtotext import SpeechToText

# Create a default solution
stt = SpeechToText()

# Start recording the text but first adjust for ambient noise
stt.adjust_for_ambient_noise(duration=1.0)
print("Говорите!")
record = stt.record_from_microphone()

# Recognize what was said
text = stt.translate(record)

print(text)
Beispiel #6
0
    def __init__(self, config_provider):

        text_to_speech = None
        if (config_provider.acting or config_provider.browser
                or config_provider.calculator or config_provider.hand_gesture
                or config_provider.happy_colour or config_provider.mixing_desk
                or config_provider.optical_character_recognition
                or config_provider.play_your_cards_right
                or config_provider.slideshow or config_provider.weather):
            from texttospeech import TextToSpeech
            text_to_speech = TextToSpeech()

        speech_to_text = None
        if (config_provider.acting or config_provider.browser
                or config_provider.calculator or config_provider.mixing_desk
                or config_provider.phrase_translation
                or config_provider.play_your_cards_right
                or config_provider.weather):
            from speechtotext import SpeechToText
            speech_to_text = SpeechToText()

        self.acting = None
        if config_provider.acting:
            from acting import Acting
            self.acting = Acting(text_to_speech, speech_to_text)

        self.browser = None
        if config_provider.browser:
            from browser import Browser
            self.browser = Browser(text_to_speech, speech_to_text)

        self.calculator = None
        if config_provider.calculator:
            from calculator import Calculator
            self.calculator = Calculator(text_to_speech, speech_to_text)

        self.hand_gesture = None
        if config_provider.hand_gesture:
            from handgesture import HandGesture
            self.hand_gesture = HandGesture(text_to_speech)

        self.happy_colour = None
        if config_provider.happy_colour:
            from happycolour import HappyColour
            self.happy_colour = HappyColour(text_to_speech)

        self.mixing_desk = None
        if config_provider.mixing_desk:
            from mixingdesk import MixingDesk
            self.mixing_desk = MixingDesk(text_to_speech, speech_to_text)

        self.optical_character_recognition = None
        if config_provider.optical_character_recognition:
            from opticalcharacterrecognition import OpticalCharacterRecognition
            self.optical_character_recognition = OpticalCharacterRecognition(
                text_to_speech)

        self.phrase_translation = None
        if config_provider.phrase_translation:
            from phrasetranslation import PhraseTranslation
            self.phrase_translation = PhraseTranslation(speech_to_text)

        self.play_your_cards_right = None
        if config_provider.play_your_cards_right:
            from playyourcardsright import PlayYourCardsRight
            self.play_your_cards_right = PlayYourCardsRight(
                text_to_speech, speech_to_text)

        self.slideshow = None
        if config_provider.slideshow:
            from slideshow import Slideshow
            self.slideshow = Slideshow(text_to_speech)

        self.television = None
        if config_provider.television:
            from television import Television
            self.television = Television()

        self.weather = None
        if config_provider.weather:
            from weather import Weather
            self.weather = Weather(text_to_speech, speech_to_text)
Beispiel #7
0
 def __init__(self):
     self.speech_to_text = SpeechToText()
     self.current_speech = None
Beispiel #8
0
from speechtotext import SpeechToText, SOLUTION_GOOGLE, SOLUTION_KALDI

stt = SpeechToText()

# Speech to text from audiofile
print("-----------------")
print("Read audio from a file (test_record.wav)")
record = stt.record_from_audiofile("test_record.wav")

text = stt.translate(record, solution=SOLUTION_KALDI)
print("Kaldi solution: {}".format(text))
text = stt.translate(record, solution=SOLUTION_GOOGLE)
print("Google solution: {}".format(text))

# Speech to text from a microphone phrase
print("-----------------")
print("Read audio from a microphone.")

print("Important: Adjust for an ambient noise first!")
stt.adjust_for_ambient_noise()
print("Adjusted for an ambient noise.")

print("Speak!")
record = stt.record_from_microphone()

text = stt.translate(record, solution=SOLUTION_KALDI)
print("Kaldi solution: {}".format(text))
text = stt.translate(record, solution=SOLUTION_GOOGLE)
print("Google solution: {}".format(text))
Beispiel #9
0
Dis_entry.grid(row=1, rowspan= 1 , columnspan = 100, ipadx = 999 , ipady = 20)
# end entry box

logging.info('Loading next word predictor')
predictor = NextWordPredictor('models/encoder.pkl', 'models/decoder.pkl',
                              'models/vocab.pkl')

if USE_CHAT:
    from alis_gpt2 import ChatGeneratorFR
    logging.info('Loading next sentence predictor')
    chat = ChatGeneratorFR(TRANSLATE_KEY)
    chat.restart_chat()

logging.info('Instanciating speech to text instance')
# Speech to text section
speech_to_text = SpeechToText()

logging.info('Start setting the keyboard up')
keyboard = Keyboard("", equation, key, predictor, speech_to_text)
keyboard.set_up_keyboard()


def input_callback():
    value = speech_to_text.recognize()
    speech_var.set(value)
    keyboard.last_input = value
    keyboard.new_sentence(value)

    if USE_CHAT:
        chat.restart_chat()
        res = chat.get_words(value)
Beispiel #10
0
def speechtotext(filename):
    STT=SpeechToText('AIzaSyAxfmMWqj3U_8UTPqIB2N9VxVkuh-_-UlQ')
    sentence=STT(filename)
    return(sentence)
Beispiel #11
0
 def __init__(self):
     self.speech_to_text = SpeechToText()
     self.current_speech = None
Beispiel #12
0
class Browser:

    MIN_LINE_LENGTH = 60
       
    def __init__(self):
        self.text_to_speech = TextToSpeech()
        self.speech_to_text = SpeechToText()
        self.category = None
        self.is_speaking = False

    # create thread for processing content
    def start(self):
        Thread(target=self._process, args=()).start()

    def _process(self):
        while True:
            if self.category:
                # obtain current category
                current_category = self.category

                # browser asks question
                self._text_to_speech("What do you want to load, buddy?")

                # user gives answer
                answer = self.speech_to_text.convert()
                if not answer: continue

                # get url from search engine
                url = search_engine(current_category, answer)
                if not url: continue

                # browser tells user that content is being retrieved
                self._text_to_speech("Cool. I will get you stuff now...")

                # get web content
                request = requests.get(url)
                soup = BeautifulSoup(request.text) 

                # get text from web content
                [s.extract() for s in soup(['style', 'script', '[document]', 'head', 'title'])]
                text = soup.getText()
                
                # speak each line of text        
                try:
                    for line in text.split('\n'):
                        if current_category != self.category: break
                                
                        if len(line) >= self.MIN_LINE_LENGTH:
                            self._text_to_speech(line)
                except:
                    print "Browser: error converting text to speech"
    
    # text to speech
    def _text_to_speech(self, text):
        self.is_speaking = True
        self.text_to_speech.convert(text)
        self.is_speaking = False

    # load
    def load(self, category):
        self.category = category

    # halt
    def halt(self):
        self.category = None
Beispiel #13
0
 def __init__(self):
     self.text_to_speech = TextToSpeech()
     self.speech_to_text = SpeechToText()
     self.category = None
     self.is_speaking = False