gpt4 book ai didi

google-api - 什么是用于 TTS(文本到语音)的 Google Cloud API?

转载 作者:行者123 更新时间:2023-12-04 07:34:16 27 4
gpt4 key购买 nike

关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。












想改进这个问题?将问题更新为 on-topic对于堆栈溢出。

2年前关闭。




Improve this question




在我的 web 应用程序中,我试图调用向 Google API 发出 HTTP 请求,该 API 需要一些文本(例如“Hello World”)并返回一个带有语音等效的 MP3 文件。

我看过这个问题:Google text to speech tts api doesn't seems to work .而这个谷歌页面:
https://cloud.google.com/translate/docs/ .

还有很多其他页面看起来已经过时了——看起来这个功能已经被谷歌删除了,或者正在另一个休息电话中?

我没有看到任何关于如何为 TTS 调用 google api 的文档(例如在 Google Translate API https://cloud.google.com/translate/ 中)。我有一个谷歌云 API 帐户和 key 。

谢谢,

最佳答案

谷歌最近发布了谷歌云文字转语音 API。

.NET 可以在此处找到 Google.Cloud.TextToSpeech 的客户端版本:
https://github.com/jhabjan/Google.Cloud.TextToSpeech.V1

以下是如何使用客户端的简短示例:

GoogleCredential credentials =
GoogleCredential.FromFile(Path.Combine(Program.AppPath, "jhabjan-test-47a56894d458.json"));

TextToSpeechClient client = TextToSpeechClient.Create(credentials);

SynthesizeSpeechResponse response = client.SynthesizeSpeech(
new SynthesisInput()
{
Text = "Google Cloud Text-to-Speech enables developers to synthesize natural-sounding speech with 32 voices"
},
new VoiceSelectionParams()
{
LanguageCode = "en-US",
Name = "en-US-Wavenet-C"
},
new AudioConfig()
{
AudioEncoding = AudioEncoding.Mp3
}
);

string speechFile = Path.Combine(Directory.GetCurrentDirectory(), "sample.mp3");

File.WriteAllBytes(speechFile, response.AudioContent);

关于google-api - 什么是用于 TTS(文本到语音)的 Google Cloud API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39087211/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com