使网站将文本转换为音频[Google Cloud Text to Speech API]

问题描述 投票:0回答:1

我是编码的初学者。我想使用Google Cloud Text to Speech API创建一个简单的网站。

  1. 带有文本框的网站
  2. 您在文本框中输入文本,然后单击“转换为音频”按钮
  3. 您可以将由Google云文本制作的mp3文件下载到语音api

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

我的搜索方式类似于“开发一个将文本转换为音频的网站”。我找到了这个网站。Creating an HTML Application to Convert Text Files to Audio Files但是,它不符合我的要求。

您能给我任何信息来建立一个将文本转换为音频的网站吗?

谢谢你。

真诚,Kazu

我已经在Google合作实验室制作了一个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')
google-cloud-platform text-to-speech google-cloud-speech google-text-to-speech
1个回答
0
投票

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

关于您需要输入框将文本转换为音频的要求。您需要遵循在GCP上部署应用程序的一般准则。Serve Machine Learning Model on App Engine Flexible Environment

因此,基本上,您的步骤将是训练模型并通过App引擎部署进行服务,或者部署将带有json负载的请求发送到文本语音API的应用程序。但是您需要做很多阅读工作。希望这会有所帮助。

© www.soinside.com 2019 - 2024. All rights reserved.