Exemplo n.º 1
0
def make_speech(message, filename):

    text_to_speech = TextToSpeechV1(
        username='******',
        password='******')

    with open(filename, 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(message,
                                      accept='audio/wav',
                                      voice="en-US_AllisonVoice"))

    play(filename)
def create_audio(events):
    text_to_speech = TextToSpeechV1(username=WATSON_USER_NAME,
                                    password=WATSON_PASSWORD,
                                    x_watson_learning_opt_out=True)

    for event in events:
        raw_data = text_to_speech.synthesize(event["summary"],
                                             accept='audio/wav',
                                             voice="ja-JP_EmiVoice")
        if is_json(raw_data):
            continue
        store_audio(raw_data, event["uid"])
        time.sleep(1)
Exemplo n.º 3
0
    def __init__(self, key, url):
        """Call super constructors and auth to IBM sdk by creating sdk stt interface

        Args:
            url (str): The IBM API url can be found in service credentials of stt service
            key (str): The IBM API key can be found in service credentials of stt service

        """
        ProcessService.__init__(self)
        SynthesizeCallback.__init__(self)
        self.url = url
        self.key = key
        self.interface = TextToSpeechV1(iam_apikey=self.key, url=self.url)
Exemplo n.º 4
0
def TTS():
    text_to_speech = TextToSpeechV1(
    username='******',
    password='******',
    x_watson_learning_opt_out=False)  # Optional flag
    print(json.dumps(text_to_speech.voices(), indent=2))
    with open(join(dirname(__file__), 'output.wav'), 'wb') as audio_file:
       audio_file.write(text_to_speech.synthesize('Hello world!', accept='audio/wav', voice="en-US_AllisonVoice"))
    with open(join(dirname(__file__), 'output.wav'),
                  'wb') as audio_file:    audio_file.write(text_to_speech.synthesize('Hello world!', accept='audio/wav',
                                           voice = "en-US_AllisonVoice"))
    print(json.dumps(text_to_speech.pronunciation('Watson', pronunciation_format='spr'), indent=2))
    print(json.dumps(text_to_speech.customizations(), indent=2))
 def __init__(self): 
     super(IBMWatsonUtility, self).__init__() 
     self.TTS = TextToSpeechV1( 
         username='******', 
         password='******', 
         x_watson_learning_opt_out=False) 
     self.STT = SpeechToTextV1( 
         username='******', 
         password='******', 
         x_watson_learning_opt_out=False) 
     self.threshold = 500 
     self.chunk_size = 1024 
     self.format = pyaudio.paInt16 
     self.rate = 44100 
Exemplo n.º 6
0
Arquivo: voice.py Projeto: k4cg/heiko
def generate_mp3(cfgobj, text, outfile):
    """
    Generate voice files
    """

    text_to_speech = TextToSpeechV1(
        iam_apikey=cfgobj["voice"]["watson_api_key"],
        url=cfgobj["voice"]["watson_endpoint"])

    with open(outfile, 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(
                text, 'audio/ogg;codecs=vorbis',
                'en-US_MichaelVoice').get_result().content)
Exemplo n.º 7
0
    def __init__(self, ):
        self.MIN_ANSWER_LEN = 5
        self.MIN_CONFIDENCE = 0.60
        self.SMALL_TALK = ['I see.', 'Got it.', 'Ok', 'Interesting']
        self.POSITIVE_REMARK = [
            "Good.", "Excellent!", "Sounds great!", "That's awesome!",
            "Wonderful!"
        ]
        self.NEGATIVE_REMARK = [
            "I'm sad to hear that.", "That doesn't sound very good.",
            "I'm sad to hear that.", "ah",
            "Someone forgot to have their coffee today"
        ]
        self.questions = [
            'Tell me about yourself',
            'Tell me about a recent project that you worked on',
            'What are your greatest weaknesses?',
            'What did you dislike the most about your last job?',
            'If you were an animal, which one would you want to be?',
            'What are your hobbies?',
            'What is your greatest professional achievement?',
            'Why do you want to work here?', 'What are your strengths?',
            'Where do you see yourself in five years?',
            'What type of work environment do you prefer?',
            "What's a time you disagreed with a decision that was made at work?",
            'Why was there a gap in your employment?',
            'Can you explain why you changed career paths?',
            'How do you deal with pressure or stressful situations?',
            'What would your first 30, 60, or 90 days look like in this role?',
            'What are your salary requirements?',
            'How many tennis balls can you fit into a limousine?',
            'Are you planning on having children?',
            'How many ping pong balls fit on a 737?',
            'Describe a difficult work situation / project and how you overcame it',
            'How are you different from the competition?',
            'Do you take work home with you?',
            'How do you view yourself? Whom do you compare yourself to?',
            'What motivates you',
            'What did you like most about your last job?',
            'What did you dislike most about your last job?',
            'Why should I take a risk on you?'
        ]
        self.text_to_speech = TextToSpeechV1(
            x_watson_learning_opt_out=True)  # Optional flag
        self.speech_to_text = SpeechToTextV1(x_watson_learning_opt_out=False)
        self.nlu = NLU(version='2017-02-27')

        self.TEMPFILE = './temp/output.wav'
        self.answers, self.sentiments = [], []
Exemplo n.º 8
0
def convert_tts(text, file_path, mp3_file_path):
    """
    Convert given text to speech audio file.
    """
    text_to_speech = TextToSpeechV1(username='******',
                                    password='******')
    voice = 'en-US_AllisonVoice'
    accept = 'audio/wav'

    with open(file_path, 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(text, voice=voice, accept=accept))

    mp3_ver = pydub.AudioSegment.from_wav(file_path)
    mp3_ver.export(mp3_file_path, format="mp3")
def generate_speech(text, proxy, no_sound=False):
    fullfile = join(dirname(__file__), "proxy.wav")
    user, passwd = get_config()
    tts = TextToSpeechV1(url=proxy,
                         username=user,
                         password=passwd,
                         x_watson_learning_opt_out=True)
    with open(fullfile, 'wb') as f:
        f.write(
            tts.synthesize(text,
                           accept='audio/wav',
                           voice="en-US_AllisonVoice"))
    if not no_sound:
        play_file(fullfile)
    print(fullfile)
def TextToSpeech(text, api, url):
    text_to_speech = TextToSpeechV1(iam_apikey=api, url=url)

    text_to_speech.set_default_headers({'x-watson-learning-opt-out': "true"})

    #voice = text_to_speech.get_voice('en-US_AllisonVoice').get_result()
    #voices = text_to_speech.list_voices().get_result()
    #print(json.dumps(voices, indent=2))
    #print(json.dumps(voice, indent=2))

    with open('test.wav', 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(
                text, 'audio/wav', 'en-US_AllisonVoice').get_result().content)
    audio_file.close()
Exemplo n.º 11
0
def generate_speech(text):
    fname = hashlib.sha256(text).hexdigest() + ".wav"
    fullfile = join(dirname(__file__), "audio", fname)
    if not exists(fullfile):
        user, passwd = get_config()
        tts = TextToSpeechV1(username=user,
                             password=passwd,
                             x_watson_learning_opt_out=True)
        with open(fullfile, 'wb') as f:
            f.write(
                tts.synthesize(text,
                               accept='audio/wav',
                               voice="en-US_AllisonVoice"))
    play_file(fullfile)
    print(fullfile)
Exemplo n.º 12
0
    def __init__(self):
        self.CHUNK = 1024
        self.BUF_MAX_SIZE = self.CHUNK * 10
        self.q = Queue(maxsize=int(round(self.BUF_MAX_SIZE / self.CHUNK)))
        self.audio_source = AudioSource(self.q, True, True)
        self.FORMAT = pyaudio.paInt16
        self.CHANNELS = 1
        self.RATE = 44100

        self.__apikey_stt = Config().Get("SpeechToText", "WatsonSTTAPIKey")
        self.__url_stt = Config().Get("SpeechToText", "WatsonSTTUrl")

        self.__apikey_tts = Config().Get("TextToSpeech", "WatsonTTSAPIKey")
        self.__url_tts = Config().Get("TextToSpeech", "WatsonTTSUrl")

        self.__voiceName = Config().Get("TextToSpeech", "WatsonVoiceName")

        self.__language_2letter_cc = Config().Get("SpeechToText",
                                                  "CountryCode2Letter")
        self.__language_4letter_cc = Config().Get("SpeechToText",
                                                  "CountryCode4Letter")
        self.__audioPlayer = Config().Get("TextToSpeech",
                                          "AudioPlayer") + " '{0}'"

        self.text_to_speech = TextToSpeechV1(url=self.__url_tts,
                                             iam_apikey=self.__apikey_tts)
        self.text_to_speech.set_default_headers(
            {'x-watson-learning-opt-out': "true"})

        self.speech_to_text = SpeechToTextV1(url=self.__url_stt,
                                             iam_apikey=self.__apikey_stt)
        self.speech_to_text.set_default_headers(
            {'x-watson-learning-opt-out': "true"})

        self.audio = pyaudio.PyAudio()

        # open stream using callback
        self.stream = self.audio.open(format=self.FORMAT,
                                      channels=self.CHANNELS,
                                      rate=self.RATE,
                                      input=True,
                                      frames_per_buffer=self.CHUNK,
                                      stream_callback=self.pyaudio_callback,
                                      start=False)
        try:
            rospy.init_node('STT_watson_node', anonymous=True)
        except:
            FileLogger().Info('already initialized')
Exemplo n.º 13
0
 def __init__(self):
     threading.Thread.__init__(self)
     self.setDaemon(
         False)  # As a single program, keep this one running all the time
     self._homeDir = os.path.expanduser("~/.sensomatic")
     self._configFileName = self._homeDir + '/config.ini'
     self._config = ConfigParser.ConfigParser()
     self._readConfig()
     self._tts = TextToSpeechV1(
         username=self._config.get('TTS', 'AuthName'),
         password=self._config.get('TTS', 'AuthSecret'),
         x_watson_learning_opt_out=False)  # Lets learn from our nonsense
     self._mqclient = mqtt.Client("TTS-%s" %
                                  self._config.get("ROOM", "Name"),
                                  clean_session=True)
     self._workingQueue = Queue.Queue()
Exemplo n.º 14
0
def play_audio(text):
    text_to_speech = TextToSpeechV1(
        username='******',
        password='******',
        x_watson_learning_opt_out=True)

    with open(join(dirname(__file__), 'resources/audio.wav'),
              'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(text,
                                      accept='audio/wav',
                                      voice="en-US_AllisonVoice"))

    wave_obj = sa.WaveObject.from_wave_file("resources/audio.wav")
    play_obj = wave_obj.play()
    play_obj.wait_done()
Exemplo n.º 15
0
def say_text(text):
    text_to_speech = TextToSpeechV1(
        username="******",
        password="******",
        x_watson_learning_opt_out=True)  # Optional flag

    # print(json.dumps(text_to_speech.voices(), indent=2))



    # print(os.getcwd().replace('\\','/'))

    with open(os.getcwd().replace('\\','/')+'/currentSpeech.wav', 'wb') as audio_file:
        audio_file.write(text_to_speech.synthesize(text, accept='audio/wav', voice="de-DE_BirgitVoice"))

    os.system("start "+os.getcwd().replace('\\','/')+'/currentSpeech.wav')
Exemplo n.º 16
0
def read_out_text(text):
    text_to_speech = TextToSpeechV1(iam_apikey=apikeys.iam_apikey,
                                    url=apikeys.url)
    with open('text.mp3', 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(
                text, 'audio/mp3', 'en-US_AllisonVoice').get_result().content)
    sound = vlc.MediaPlayer('text.mp3')
    vlc_instance = vlc.Instance()
    player = vlc_instance.media_player_new()
    media = vlc_instance.media_new('text.mp3')
    player.set_media(media)
    player.play()
    sleep(.5)
    duration = player.get_length() / 1000
    sleep(duration)
Exemplo n.º 17
0
def text_to_speech(text_to_speak, voice_to_use, file_name):
    """Use Watson Text to Speech to convert text to specified voice
       and save to a WAV file."""
    # create Text to Speech client
    tts = TextToSpeechV1(
        iam_apikey=keys.text_to_speech_key,
        url=
        'https://api.eu-gb.text-to-speech.watson.cloud.ibm.com/instances/000593f3-0574-41fb-a2fa-1587131a51ae'
    )

    # open file and write the synthesized audio content into the file
    with open(file_name, 'wb') as audio_file:
        audio_file.write(
            tts.synthesize(text_to_speak,
                           accept='audio/wav',
                           voice=voice_to_use).get_result().content)
Exemplo n.º 18
0
def text_to_speech(text):
    _API_KEY = ''
    KEY_FILE = "keys.txt"
    with open(KEY_FILE, "r") as key_file:
        content = key_file.read().splitlines()
        _API_KEY = content[0]

    service = TextToSpeechV1(
        iam_apikey=_API_KEY,
        url='https://gateway-wdc.watsonplatform.net/text-to-speech/api')

    with open(join(dirname(__file__), './' + 'output' + '.wav'),
              'wb') as audio_file:
        response = service.synthesize(text,
                                      accept='audio/wav',
                                      voice="en-US_MichaelVoice").get_result()
        audio_file.write(response.content)
Exemplo n.º 19
0
def watson_speech(answer):
    print("[Checkpoint 08] Speaking Answer: ", str(answer))
    text_to_speech = TextToSpeechV1(iam_apikey=key1, url=url1)

    speech_text = str(answer)

    with open('answer.mp3', 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(
                speech_text, 'audio/mp3',
                'en-US_AllisonVoice').get_result().content)

    # TODO: Play the audio file here with OS command
    os.system("omxplayer answer.mp3")

    # return to the server
    return
Exemplo n.º 20
0
def call_text2speech(text_stmt):
    Config=configparser.ConfigParser()
    Config.read("watson.ini")
    userid=ConfigSectionMap(Config,"Text to Speech-RAI")['username']
    pwd=ConfigSectionMap(Config,"Text to Speech-RAI")['password']

    text_to_speech = TextToSpeechV1(username=userid,password=pwd,x_watson_learning_opt_out=True)  # Optional flag
    #print(json.dumps(text_to_speech.voices(), indent=2))

    try:
        with open(join(dirname(__file__), 'output.wav'),'wb') as audio_file:
            audio_file.write(text_to_speech.synthesize(text_stmt, accept='audio/wav',voice="en-US_AllisonVoice"))

        print(json.dumps(text_to_speech.pronunciation('Watson', pronunciation_format='spr'), indent=2))
        #print(json.dumps(text_to_speech.customizations(), indent=2))
    except:
        return
Exemplo n.º 21
0
def downloadAndPlayAudio(tweetText):
    print('Now playing: ' + tweetText)
    text_to_speech = TextToSpeechV1(
        username='******',
        password='******',
        x_watson_learning_opt_out=True)  # Optional flag

    with open(join(dirname(__file__), 'output.ogg'), 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(tweetText,
                                      accept='audio/ogg;codecs=vorbis',
                                      voice="en-US_MichaelVoice"))
        #voice="en-US_AllisonVoice"))
    pygame.mixer.music.load('output.ogg')
    pygame.mixer.music.play()
    while pygame.mixer.music.get_busy():
        #print "Playing", pygame.mixer.music.get_pos()
        time.sleep(0.020)
Exemplo n.º 22
0
def callback(data):

    #rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

    text_to_speech = TextToSpeechV1(
        username='******',
        password='******',
        x_watson_learning_opt_out=True)
    # Optional flag

    #print(json.dumps(text_to_speech.voices(), indent=2))

    with open(join(dirname(__file__), 'answer.wav'), 'wb') as audio_file:
        audio_file.write(
            text_to_speech.synthesize(data.data,
                                      accept='audio/wav',
                                      voice="en-US_AllisonVoice"))

    play_audio()
Exemplo n.º 23
0
def textToSpeech(message):
    result = None
    if message:
        ibm_config = getConfigIBM()
        username = ibm_config['ibm_texttospeech_username']
        password = ibm_config['ibm_texttospeech_password']

        text_to_speech = TextToSpeechV1(username=username,
                                        password=password,
                                        x_watson_learning_opt_out=True)

        try:
            result = text_to_speech.synthesize(message,
                                               accept='audio/wav',
                                               voice='en-US_AllisonVoice')
        except:
            pass

    return result
Exemplo n.º 24
0
def pass_to_texttospeach(username, password, text):
    RATE = 22050
    SAMPWIDTH = 2
    NCHANNELS = 1
    CHANK = 2048
    ACCEPT = 'audio/wav'

    texttospeach = TextToSpeechV1(username=username, password=password)

    response = texttospeach.synthesize(text=text, accept=ACCEPT)
    audio = PyAudio()
    stream = audio.open(format=audio.get_format_from_width(SAMPWIDTH),
                        channels=NCHANNELS,
                        rate=RATE,
                        output=True)
    stream.write(response)
    stream.stop_stream()
    stream.close()
    audio.terminate()
Exemplo n.º 25
0
 def getSpeechFile(self, t, e):
     output_wav = "./output/output-{}.wav".format(
         time.strftime("%Y%m%d-%H%M%S"))
     SSML = '<express-as type="{}">{}</express-as>'.format(e, t)
     if (e == "Angry"):
         SSML = '<voice-transformation type="Custom" pitch="50%" pitch_range="80%" rate="40%" glottal_tension="100%" breathiness="60%">{}</voice-transformation>'.format(
             t)
     elif (e == "Supportive"):
         SSML = '<voice-transformation type="Custom" glottal_tension="-80%">{}</voice-transformation>'.format(
             t)
     tts = TextToSpeechV1(iam_apikey=self.key, url=self.url)
     # result = tts.list_voices().get_result()
     with open(output_wav, 'wb') as audio_file:
         response = tts.synthesize(SSML,
                                   accept='audio/wav',
                                   voice="en-US_AllisonVoice").get_result()
         audio_file.write(response.content)
     # pronunciation = tts.get_pronunciation('Watson', format='spr').get_result()
     return output_wav
Exemplo n.º 26
0
 def __init__(self):
     self.text_to_speech = TextToSpeechV1(
         iam_apikey='nBVvz1-p4Q3F0rF_L8c0UmCfirPNfIKaVO32prppKCzR',
         url='https://stream.watsonplatform.net/text-to-speech/api')
     self.localDir = os.path.dirname(__file__)
     self.absDir = os.path.join(os.getcwd(), self.localDir)
     self.pitchLookup = {
         "F": -100,
         "F#": -80,
         "G": -60,
         "G#": -39,
         "A": -19,
         "A#": 3,
         "B": 23,
         "C": 44,
         "C#": 66,
         "D": 90
     }
     self.fileNum = 1
Exemplo n.º 27
0
def textToSpeech(self):
    text_to_speech = TextToSpeechV1(
        username="******",
        password="******",
    )

    print(json.dumps(text_to_speech.voices(), indent=2))
    p = pyaudio.PyAudio()

    stream = p.open(format=p.get_format_from_width(2),
                    channels=1,
                    rate=22050,
                    output=True)

    stream.write(
        text_to_speech.synthesize(self,
                                  accept='audio/wav',
                                  voice="en-GB_KateVoice"))

    p.terminate()
Exemplo n.º 28
0
def getSpeechFromText():
    tts_kwargs = {
        'username': textToSpeechUser,
        'password': textToSpeechPassword,
        'iam_apikey': textToSpeechIAMKey,
        'url': textToSpeechUrl
    }

    inputText = request.form.get('text')
    ttsService = TextToSpeechV1(**tts_kwargs)

    def generate():
        audioOut = ttsService.synthesize(inputText, 'audio/wav',
                                         'en-US_AllisonVoice').get_result()

        data = audioOut.content

        yield data

    return Response(response=generate(), mimetype="audio/x-wav")
Exemplo n.º 29
0
def text_to_speech(text, file_path, auth_file):
    """
    Convert given text to speech audio file saved in given path.
    """
    try:
        with open(auth_file) as authfile:
            auth_data = json.load(authfile)
            username = auth_data['tts']['username']
            password = auth_data['tts']['password']
    except:
        raise
    tts = TextToSpeechV1(username=username, password=password)
    voice = 'en-US_MichaelVoice'
    accept = 'audio/wav'
    outdir = os.path.dirname(file_path)
    if not os.path.exists(outdir):
        os.makedirs(outdir)
    with open(file_path, 'wb') as audio_file:
        audio_file.write(tts.synthesize(text, voice=voice, accept=accept))
    return file_path
    def __init__(self, directory):
        # Open STT Service
        with open(join(directory, "sttConfig.json")) as confile:
            stt_config = json.load(confile)['credentials']
        self.speechToText = SpeechToTextV1(username=stt_config['username'],
                                           password=stt_config['password'])

        # Open TTS Service
        with open(join(directory, "ttsConfig.json")) as confile:
            tts_config = json.load(confile)['credentials']
        self.textToSpeech = TextToSpeechV1(username=tts_config['username'],
                                           password=tts_config['password'])

        # Open the Dialog Service
        with open(join(directory, "dialogConfig.json")) as confile:
            dialog_config = json.load(confile)['credentials']
        self.dialogID = dialog_config['id']
        self.dialog = DialogV1(username=dialog_config['username'],
                               password=dialog_config['password'])
        self.response = self.dialog.conversation(self.dialogID)
        self.workingDirectory = directory