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