I'm a beginner in coding. I would like to make a simple website using Google Cloud Text to Speech API.
- a web site with a text box
- you write a text in the text box and click a button "convert to audio"
- you can download mp3 file which is made by google cloud text to speech api
I have read Google Cloud Text to Speech API's official site, but couldn't find a solution.
I have searched like "develop a website converting text to audio". I found this site. Creating an HTML Application to Convert Text Files to Audio Files However, it didn't meet my request.
Could you give me any information to develop a website converting text to audio?
Thank you in advance.
Sincerely, Kazu
I have made a python program on Google Colaboratory. I would like to do the same thing on a website.
from google.colab import drive
drive.mount('/content/drive')
!cp ./drive/'My Drive'/credential.json ./credential.json
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="credential.json"
f= open("text.ssml","w+")
f.write('<speak><prosody rate="slow">hello world</prosody></speak>')
f.close()
!pip install google-cloud-texttospeech
#!/usr/bin/env python
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
with open('text.ssml', 'r') as f:
ssml = f.read()
input_text = texttospeech.types.SynthesisInput(ssml=ssml)
voice = texttospeech.types.VoiceSelectionParams(language_code='en-US', name="en-US-Wavenet-A")
audio_config = texttospeech.types.AudioConfig(audio_encoding=texttospeech.enums.AudioEncoding.MP3)
response = client.synthesize_speech(input_text, voice, audio_config)
with open('output.mp3', 'wb') as out:
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')
from google.colab import files
files.download('output.mp3')