Ejemplo n.º 1
0
    # voice gender ("neutral")
    voice = texttospeech.VoiceSelectionParams(
        language_code=language,
        ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL)

    # Select the type of audio file you want returned
    audio_config = texttospeech.AudioConfig(
        audio_encoding=texttospeech.AudioEncoding.MP3)

    # Perform the text-to-speech request on the text input with the selected
    # voice parameters and audio file type
    response = client.synthesize_speech(input=synthesis_input,
                                        voice=voice,
                                        audio_config=audio_config)

    # The response's audio_content is binary.
    with open('audio/{}.mp3'.format(text), 'wb') as out:
        # Write the response to the output file.
        out.write(response.audio_content)


if __name__ == "__main__":

    # Get list of korean words and get the audio for each word
    words = get_hangeul()

    # Create the dataframe of words and save it as .csv file
    dictionary = pd.DataFrame(
        words, columns=['word', 'korean', 'pronunciation', 'meaning'])
    dictionary.to_csv('dictionary.csv', index=False)