c# - 无法在 c# 中使用 Google.Cloud.TextToSpeech.V1 指定音频配置文件
问题描述
我正在尝试使用 Google.Cloud.TextToSpeech.V1 将文本转换为音频。它工作正常,但我不知道如何在我在 Node.js 和 python 中找到代码时使用 c# 指定要使用的音频配置文件但在 c# 中没有任何内容这是我的代码
static void Main(string[] args)
{
List<Word> lst = IntialData();
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\Users\Admin\TextToSpeechApiDemo\key.json");
var client = TextToSpeechClient.Create();
// The input to be synthesized, can be provided as text or SSML.
foreach (Word item in lst)
{
var input = new SynthesisInput
{
Text = item.Name,
};
// Build the voice request.
var voiceSelection = new VoiceSelectionParams
{
LanguageCode = "ar",
//SsmlGender = SsmlVoiceGender.Female,
Name = "ar-XA-Wavenet-A"
};
// Specify the type of audio file.
var audioConfig = new AudioConfig
{
AudioEncoding = AudioEncoding.Linear16,
};
// Perform the text-to-speech request.
var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
// Write the response to the output file.
using (var output = File.Create(@"E:\Noursound\sim\ar-XA-Wavenet-A\" + item.Id.ToString() + ".wav"))
{
response.AudioContent.WriteTo(output);
}
}
}
我在 python 中找到了这段代码,他设置了 effects_profile_id
audio_config = texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.MP3,
effects_profile_id=[effects_profile_id],
我怎么能用c#做到这一点
解决方案
问题出在我使用的 NuGet 包的版本中 1.0.0-beta01 ,它没有 EffectsProfileId 属性,但在将其更新为 Google.Cloud.TextToSpeech.V1 版本 2.3.0 后,我找到了该属性。
using Google.Cloud.TextToSpeech.V1;
class Program
{
static void Main(string[] args)
{
var config = new AudioConfig
{
AudioEncoding = AudioEncoding.Mp3,
EffectsProfileId = { "your profile ID" }
};
}
}
我在 github 上为此创建了 git issue 这是一个链接!
推荐阅读
- google-analytics - 跟踪排除页面的事件
- jenkins - 谷歌云控制台詹金斯密码
- sql - 为什么在 Druid 中无法删除数据?
- swift - 快速 4 UIPageViewControler
- android - 获取 Flowable 订阅方法的结果
- php - 如何在 sql 查询的一部分中正确地将 2 个 foreach 循环组合在一起?
- .htaccess - .php 扩展名已隐藏时的 URL 重写
- gatsby - gatsbyjs:多次使用graphql,还是一次使用并通过上下文传递结果?
- javascript - 如何更新异步函数中的 javascript 变量的值
- typescript - 文档类型不仅仅是“对象”?