0

I'm starting to know how to use google APIs modifying the python example code of the texttospeech API I found an issue, when I use ssml languaje in a txt file to pass the text to the API the resultant mp3 audio changed the character 'é' with the sentence 'derechos de autor' and the character 'á' with a silence. That only happens when I read the text from file, if i provide the ssml sentence direct to the applicacion by argunment when calling it this change doesn't happens. I searched for this issue and I didn't find it, colud anyone give a hint of that is going on here?

This is the function that takes the ssml texto from the console, and creates the correct mp3 audio file:

def synthesize_ssml(ssml, output):
    from google.cloud import texttospeech as texttospeech   
    client = texttospeech.TextToSpeechClient()
    input_text = texttospeech.types.SynthesisInput(ssml=ssml)
    voice = texttospeech.types.VoiceSelectionParams(language_code='es-ES')
    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)
    response = client.synthesize_speech(input_text, voice, audio_config)
    with open(output, 'wb') as out:
        out.write(response.audio_content)
        print('Audio content written to file "%s"' % output)

And this is the function that takes the ssml from a file, the same text, produce different audio files:

def synthesize_ssml_file(input, output):
    from google.cloud import texttospeech as texttospeech   
    with open(input,'r') as inp:
        input_text=texttospeech.types.SynthesisInput(ssml=str(inp.read()))
    client = texttospeech.TextToSpeechClient()
    voice = texttospeech.types.VoiceSelectionParams(language_code='es-ES')
    audio_config = texttospeech.types.AudioConfig(
        audio_encoding=texttospeech.enums.AudioEncoding.MP3)
    response = client.synthesize_speech(input_text, voice, audio_config)
    with open(output, 'wb') as out:
        out.write(response.audio_content)
        print('Audio content written to file "%s"' % output)
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Ic3_2K
  • 1
  • I've formatted your code based on how you used tabs and spaces. Please review the code to make sure it appears as intended. – Nisse Engström Sep 08 '18 at 16:23
  • Now I'm even more confused, executing this script on another computer the resulting audio is correct. So there is something in the first PC that causes the audio file generated when using ssml taken from a file to be different from the one generated when passing the ssml in the arguments of the script – Ic3_2K Sep 10 '18 at 10:52

0 Answers0