Created
June 27, 2020 02:01
-
-
Save sahya/37e315ac6de4bf97beba47f8c6e43081 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
def synthesize_text(text, path): | |
import os | |
from google.cloud import texttospeech | |
from pydub import AudioSegment | |
import pathlib | |
client = texttospeech.TextToSpeechClient() | |
input_text = texttospeech.types.SynthesisInput(text=text) | |
voice = texttospeech.types.VoiceSelectionParams( | |
language_code='ja-jp', name='ja-jp-Wavenet-B') | |
audio_config = texttospeech.types.AudioConfig( | |
audio_encoding=texttospeech.enums.AudioEncoding.LINEAR16, | |
speaking_rate=1.5) | |
response = client.synthesize_speech(input_text, voice, audio_config) | |
with open(path + '.wav', 'wb') as out: | |
out.write(response.audio_content) | |
audio1 = AudioSegment.from_wav(path + '.wav') | |
audio2 = AudioSegment.from_wav(path + '_all.wav') | |
audio = audio2 + audio1 | |
audio.export(path + '.mp3', format='mp3') | |
# os.remove(path + '.wav') | |
if __name__ == '__main__': | |
with open('scripts.txt', mode='rt', encoding='utf-8') as fi: | |
print(fi) | |
path = "/home/sayaka/sample01" | |
synthesize_text(fi, path) | |
import os | |
os.remove(path + '.wav') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment