当前位置: 首页 > 知识库问答 >
问题:

如何访问谷歌文本到语音beta功能(2021年3月1日发布)

孙辰阳
2023-03-14

2021年3月1日,谷歌文本到语音发布了测试版功能,包括对ssml的支持

我希望使用这些测试版功能,但我不知道它们发布到了哪个频道,也不知道如何访问它们。我在文档中没有找到任何能让我找到它们的面包屑。

我注意到在TTS产品主页上,演示功能使用了v1beta1,但不支持

也就是说,对于ssml:

<speak>
Blah Blah English Text. <voice name="ko-KR-Wavenet-D"> Blah Blah Korean Text.</voice> <break time="400ms" /> Blah Blah English Text.
</speak>

演示显示了以下json请求正文:

{
  "audioConfig": {
    "audioEncoding": "LINEAR16",
    "pitch": 0,
    "speakingRate": 1
  },
  "input": {
    "ssml": "<speak> Blah Blah English Text. Blah Blah Korean Text. <break time=\"400ms\" /> Blah Blah English Text. </speak>"
  },
  "voice": {
    "languageCode": "en-US",
    "name": "en-US-Wavenet-D"
  }
}

我们在自己的脚本中尝试了使用google文本到语音api从csv提示表生成音频,历史上我们一直使用通用版本。当我们切换到v1beta1时,脚本仍然有效,但是

我们的脚本使用:const textToSpeech=require(“@google cloud/text-to-speech”) 和常规版本const client=new textToSpeech。TextToSpeechClient()

我们一直在尝试使用const client=new textToSpeech访问3月1日的测试版功能。v1beta1。TextToSpeechClient()


共有1个答案

楚硕
2023-03-14

根据文本到语音API的发布说明

SSML的文档说

您可以参考下面的节点。js代码并输出音频文件。

tts1。js

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');
// Import other required libraries
const fs = require('fs');
const util = require('util');
// Creates a client
const client = new textToSpeech.v1beta1.TextToSpeechClient();
async function quickStart() {
 // The text to synthesize


 const ssml =  '<speak>And then she asked, <voice name="en-IN-Wavenet-D"> where were you yesterday </voice><break time="250ms"/> in her sweet and gentle voice.</speak>'

 // Construct the request
 const request = {
   input: {ssml: ssml},
   // Select the language and SSML voice gender (optional)
   voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
   // select the type of audio encoding
   audioConfig: {audioEncoding: 'MP3'},
 };

 // Performs the text-to-speech request
 const [response] = await client.synthesizeSpeech(request);
 // Write the binary audio content to a local file
 const writeFile = util.promisify(fs.writeFile);
 await writeFile('output.mp3', response.audioContent, 'binary');
 console.log('Audio content written to file: output.mp3');
}
quickStart();

输出mp3文件:output1(使用v1beta1)

我还尝试在节点中不使用v1beta1版本。js,工作正常。

tts2。js:

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Import other required libraries
const fs = require('fs');
const util = require('util');
// Creates a client
const client = new textToSpeech.TextToSpeechClient();
async function quickStart() {
 // The text to synthesize


 const ssml =  '<speak>And then she asked, <voice name="en-IN-Wavenet-D"> where were you yesterday </voice><break time="250ms"/> in her sweet and gentle voice.</speak>'

 // Construct the request
 const request = {
   input: {ssml: ssml},
   // Select the language and SSML voice gender (optional)
   voice: {languageCode: 'en-US', ssmlGender: 'NEUTRAL'},
   // select the type of audio encoding
   audioConfig: {audioEncoding: 'MP3'},
 };

 // Performs the text-to-speech request
 const [response] = await client.synthesizeSpeech(request);
 // Write the binary audio content to a local file
 const writeFile = util.promisify(fs.writeFile);
 await writeFile('output.mp3', response.audioContent, 'binary');
 console.log('Audio content written to file: output.mp3');
}
quickStart();

输出mp3文件:输出(不含v1beta1版本)

除此之外,我想通知你,我也尝试过使用Python客户端库,它也像预期的那样工作。

file1.py

from google.cloud import texttospeech

# Instantiates a client
client = texttospeech.TextToSpeechClient()

# Set the text input to be synthesized
synthesis_input = texttospeech.SynthesisInput(
  
 ssml=  '<speak>And then she asked, <voice name="en-IN-Wavenet-D"> where were you yesterday</voice><break time="250ms"/> in her sweet and gentle voice.</speak>'
    )

# Build the voice request, select the language code ("en-US") and the ssml
# voice gender ("neutral")
voice = texttospeech.VoiceSelectionParams(
   language_code="en-US", ssml_gender=texttospeech.SsmlVoiceGender.NEUTRAL
)

# Select the type of audio file you want returned
audio_config = texttospeech.AudioConfig(
   audio_encoding=texttospeech.AudioEncoding.MP3
)

# Perform the text-to-speech request on the text input with the selected
# voice parameters and audio file type
response = client.synthesize_speech(
   input=synthesis_input, voice=voice, audio_config=audio_config
)

# The response's audio_content is binary.
with open("output.mp3", "wb") as out:
   # Write the response to the output file.
   out.write(response.audio_content)
   print('Audio content written to file "output.mp3"')

输出文件:输出(使用Python)

 类似资料:
  • 我想通过谷歌语音输入将日期作为用户的文本。所以当用户说: 2022年7月8日 然后它会以格式拆分该字符串。如何获取?我应该使用任何其他方法通过语音输入获取日期吗?

  • 我正在使用谷歌云语音到文本AP,并试图转录长音频文件。但是,无法检测到桶中的音频文件。我得到一个错误,说明:IOError:[Errno 2]没有这样的文件或目录: transcribe_gcs(gcs_uri):

  • Android谷歌语音转文本SDK,语音录制由SDK控制。我需要将其设置为手动按钮,用于启动和停止语音录制,以便将语音转换为文本。例如:当单击按钮开始语音识别时,它会继续录制音频,直到单击停止按钮。但在android SDK中,它会自动停止录制并将录制的音频传递给处理。

  • 工单 【新增】批量编辑工单新增修改工单分类功能 客服通过工单列表多选工单进行批量编辑时,可通过“工单分类”对选中的工单进行修改,修改分类时,若修改后的工单分类模板,含原工单中不存在或未填写的必填字段内容,则该字段为空并可以保存成功。 【新增】自定义字段权限,增加问题描述的权限设置 对工单自定义字段-自定义字段权限设置,新增问题描述的权限设置,可对指定的权限组,将问题描述设置为只读或读写权限,权限组

  • 在线客服 【新增】H5半屏组件 1、客户可以通过接口传参的方式来设定H5聊天组件的弹窗高度,新增参数expand_size, half为半屏,full为全屏,默认为全屏。 2、half有两种弹出状态,通过点击相应区域可以相互切换,分别是左图和右图 3、在指定half的时候,建议同时开启auto_ expand传true,落地时将会为左图的微弹状态,增强用户的使用体验。 4、可以通过h5渠道设置控制

  • 在线客服 【新增】人工满意度评价增加10分模式(支持PC、H5客户端) 人工满意度评价增加10分模式,客户可以选择使用5星模式或者10分模式,10分模式支持计算NPS值。本次支持PC、H5客户端使用。 工作台支持评价模式筛选查看 人工满意度评价统计增加10分模式指标,好评(9-10分)、中评(7-8分)、差评(0-6分)。支持NPS值计算:(好评/10分评价总数)×100%-(差评/10分评价总数