-
-
Save kelciour/489fbc75006b0ff1dc2b58bb9ee2f875 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
import os | |
from google.cloud import texttospeech | |
client = texttospeech.TextToSpeechClient() | |
voice = texttospeech.types.VoiceSelectionParams( | |
language_code='en-US', | |
ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) | |
audio_config = texttospeech.types.AudioConfig( | |
audio_encoding=texttospeech.enums.AudioEncoding.MP3) | |
def generate_audio(text, output_filename): | |
input_text = texttospeech.types.SynthesisInput(text=text) | |
response = client.synthesize_speech(input_text, voice, audio_config) | |
# The response's audio_content is binary. | |
with open(output_filename, 'wb') as out: | |
out.write(response.audio_content) | |
OUTPUT_FILE_PATTERN = "audio/glossika-level%d-day%03d.mp3" | |
TEXT_PATTERN = "GSR. Glossika spaced repetition training. Fluency %d. Russian to English. Day %d" | |
def main(): | |
if not os.path.exists('audio'): | |
os.makedirs('audio') | |
for level in range(1, 4): | |
for day in range(1, 105): | |
print (level, day) | |
text = TEXT_PATTERN % (level, day) | |
out_file = OUTPUT_FILE_PATTERN % (level, day) | |
generate_audio(text, out_file) | |
main() |
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
import os | |
from google.cloud import texttospeech | |
client = texttospeech.TextToSpeechClient() | |
voice = texttospeech.types.VoiceSelectionParams( | |
language_code='en-US', | |
ssml_gender=texttospeech.enums.SsmlVoiceGender.FEMALE) | |
audio_config = texttospeech.types.AudioConfig( | |
audio_encoding=texttospeech.enums.AudioEncoding.MP3) | |
def generate_audio(text, output_filename): | |
input_text = texttospeech.types.SynthesisInput(text=text) | |
response = client.synthesize_speech(input_text, voice, audio_config) | |
# The response's audio_content is binary. | |
with open(output_filename, 'wb') as out: | |
out.write(response.audio_content) | |
OUTPUT_FILE_PATTERN = "audio/glossika-level%d-%03d-%s.mp3" | |
TEXT_PATTERN_A = "The GMS method. Fluency %d. Russian, English, English. Dialog %d." | |
TEXT_PATTERN_B = "The GMS method. Fluency %d. Russian, pause, English. Dialog %d." | |
TEXT_PATTERN_C = "The GMS method. Fluency %d. English. Dialog %d." | |
def main(): | |
if not os.path.exists('audio'): | |
os.makedirs('audio') | |
for n in range(1, 3001, 50): | |
level = n // 1000 + 1 | |
print (level, n) | |
text = TEXT_PATTERN_A % (level, n) | |
out_file = OUTPUT_FILE_PATTERN % (level, n, 'A') | |
generate_audio(text, out_file) | |
text = TEXT_PATTERN_B % (level, n) | |
out_file = OUTPUT_FILE_PATTERN % (level, n, 'B') | |
generate_audio(text, out_file) | |
text = TEXT_PATTERN_C % (level, n) | |
out_file = OUTPUT_FILE_PATTERN % (level, n, 'C') | |
generate_audio(text, out_file) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment