Exemplo n.º 1
0
 def say(self, text):
     t = TextToSpeech(self.config, text)
     t.start()
Exemplo n.º 2
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)
Exemplo n.º 3
0
import os
import simpleaudio as sa

from texttospeech import TextToSpeech
from tempfile     import NamedTemporaryFile

# Utility function to play .wav files
def play_wav(filename):
    wave_obj = sa.WaveObject.from_wave_file(filename)
    play_obj = wave_obj.play()
    play_obj.wait_done()  # Wait until sound has finished playing

# Create a default solution
tts = TextToSpeech()

# Read what needs to be synthesized
print("Введите путь до файла с текстом для синтеза: ")
with open(input(), mode="r") as f:
    text = f.readline()

# Synthesize audiodata and write them to temporary file
audiodata = tts.synthesize(text)
with NamedTemporaryFile(mode="wb") as f:
    f.write(audiodata.get_wav_data())
    audiopath = os.path.abspath(f.name)

    # Play the file
    play_wav(audiopath)
Exemplo n.º 4
0
from texttospeech import TextToSpeech

tts = TextToSpeech()
audiodata = tts.synthesize("привет мир, меня зовут Александр!")
with open("out.wav", mode="wb") as f:
    f.write(audiodata.get_wav_data())
Exemplo n.º 5
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
Exemplo n.º 6
0
 def __init__(self):
     self.text_to_speech = TextToSpeech()
     self.speech_to_text = SpeechToText()
     self.category = None
     self.is_speaking = False