制作一个将文本转换为音频的网站 [Google Cloud Text to Speech API]

Make a website converting text to audio [Google Cloud Text to Speech API]

我是编码初学者。我想使用 Google Cloud Text to Speech API.

制作一个简单的网站
  1. 带有文本框的网站
  2. 你在文本框中写了一段文字,然后点击了一个按钮"convert to audio"
  3. 您可以下载由google cloud text to speech api
  4. 制作的mp3文件

我已阅读 Google Cloud Text to Speech API's official site,但找不到解决方案。

我搜索过 "develop a website converting text to audio"。 我找到了这个网站。 Creating an HTML Application to Convert Text Files to Audio Files 但是,它不符合我的要求。

你能给我任何信息来开发一个将文本转换为音频的网站吗?

提前致谢。

此致 Kazu

我在 Google Colaboratory 上制作了一个 python 程序。我想在网站上做同样的事情。

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')

为了实现您想要的,正如您所说,您是编码新手,第一件事就是研究 GCP 文本转语音 API。一个好的第一步是遵循可用的快速入门教程 Using client libraries text-to-speech

至于你要求一个输入框把文字转成音频。您需要遵循在 GCP 上部署应用程序的一般准则。 Serve Machine Learning Model on App Engine Flexible Environment

所以基本上你的步骤是训练一个模型并通过 App 引擎部署提供服务,或者部署一个应用程序,该应用程序将带有 json 有效负载的请求发送到文本到语音 API .但是你需要做相当多的阅读。希望这有帮助。

如果您想要灵活地处理多个 TTS(文本到语音)提供商(我们至少有 4 个),并增强语音发现,您可能需要查看 www.api.audio 这是一个例子 https://docs.api.audio/recipes/create-engaging-newscast