我想通过Google Cloud text- to -speech API使用SSML markers来请求音频流中这些标记的计时。这些时间戳是必需的,以便向用户提供效果、单词/部分突出显示和反馈的提示。
我发现this question是相关的,尽管问题指的是每个单词的时间戳,而不是SSML <mark>
标记。
下面的API请求返回OK,但显示缺少请求的标记数据。这是在使用Cloud Text-to-Speech API v1
。
{
"voice": {
"languageCode": "en-US"
},
"input": {
"ssml": "<speak>First, <mark name=\"a\"/> second, <mark name=\"b\"/> third.</speak>"
},
"audioConfig": {
"audioEncoding": "mp3"
}
}
响应:
{
"audioContent":"//NExAAAAANIAAAAABcFAThYGJqMWA..."
}
其仅提供没有任何上下文信息的合成音频。
是否有我忽略的API请求可以公开有关这些标记的信息,例如IBM Watson和Amazon Polly的情况。
发布于 2020-10-01 16:37:11
看起来这在Cloud Text-to-Speech API v1beta1
中得到了支持:https://cloud.google.com/text-to-speech/docs/reference/rest/v1beta1/text/synthesize#TimepointType
您可以使用https://texttospeech.googleapis.com/v1beta1/text:synthesize
。将TimepointType
设置为SSML_MARK
。如果不设置该字段,则默认不返回时间点。
发布于 2021-10-09 03:31:30
在撰写本文时,时间点数据已经在谷歌云text-to-speech的v1beta1
版本中可用。
除了默认的访问权限之外,我不需要登录任何额外的开发者程序就可以访问测试版。
在Python中的导入(例如)来自:
from google.cloud import texttospeech as tts
至:
from google.cloud import texttospeech_v1beta1 as tts
很好很简单。
我需要修改发送合成请求的默认方式,使其包含enable_time_pointing
标志。
我发现,在浏览machine-readable API description here和阅读Python库代码的过程中,我已经下载了这些代码。
谢天谢地,在普遍可用的版本中的源代码也包括v1beta
版本-谢谢谷歌!
我已经在下面放了一个可运行的示例。运行这段代码所需的身份验证和设置与一般的文本到语音转换示例需要的身份验证和设置相同,您可以按照官方文档进行操作。
下面是它为我做的事情(为了可读性进行了轻微的格式化):
$ python tools/try-marks.py
Marks content written to file: .../demo.json
Audio content written to file: .../demo.mp3
$ cat demo.json
[
{"sec": 0.4300000071525574, "name": "here"},
{"sec": 0.9234582781791687, "name": "there"}
]
示例如下:
import json
from pathlib import Path
from google.cloud import texttospeech_v1beta1 as tts
def go_ssml(basename: Path, ssml):
client = tts.TextToSpeechClient()
voice = tts.VoiceSelectionParams(
language_code="en-AU",
name="en-AU-Wavenet-B",
ssml_gender=tts.SsmlVoiceGender.MALE,
)
response = client.synthesize_speech(
request=tts.SynthesizeSpeechRequest(
input=tts.SynthesisInput(ssml=ssml),
voice=voice,
audio_config=tts.AudioConfig(audio_encoding=tts.AudioEncoding.MP3),
enable_time_pointing=[
tts.SynthesizeSpeechRequest.TimepointType.SSML_MARK]
)
)
# cheesy conversion of array of Timepoint proto.Message objects into plain-old data
marks = [dict(sec=t.time_seconds, name=t.mark_name)
for t in response.timepoints]
name = basename.with_suffix('.json')
with name.open('w') as out:
json.dump(marks, out)
print(f'Marks content written to file: {name}')
name = basename.with_suffix('.mp3')
with name.open('wb') as out:
out.write(response.audio_content)
print(f'Audio content written to file: {name}')
go_ssml(Path.cwd() / 'demo', """
<speak>
Go from <mark name="here"/> here, to <mark name="there"/> there!
</speak>
""")
https://stackoverflow.com/questions/57381977
复制相似问题