【问题标题】:How do I set credentials for google speech to text without setting environment variable?如何在不设置环境变量的情况下将谷歌语音的凭据设置为文本?
【发布时间】:2018-09-17 21:27:48
【问题描述】:

有使用该库的 C# 示例client-libraries-usage-csharp

还有如何设置环境变量的例子

导出 GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

如何在不设置环境变量的情况下将谷歌语音的凭据设置为文本?

有点像这样:

var 凭证 = ...create(file.json); var speech = SpeechClient.Create(credentials);

【问题讨论】:

    标签: c# .net google-app-engine speech-recognition speech-to-text


    【解决方案1】:
    using Grpc.Auth;
    

    然后

    string keyPath = "key.json";
    
    GoogleCredential googleCredential;
    using (Stream m = new FileStream(keyPath, FileMode.Open))
        googleCredential = GoogleCredential.FromStream(m);
    var channel = new Grpc.Core.Channel(SpeechClient.DefaultEndpoint.Host,
        googleCredential.ToChannelCredentials());
    var speech = SpeechClient.Create(channel);
    

    【讨论】:

    • 在课堂上 SpeechClient public static SpeechClient Create(); 持续版本。我怎么能把channel
    【解决方案2】:

    除非您在 GCP 服务上运行应用程序,否则除了设置环境变量之外,没有其他方法可以获取客户端库的服务帐户凭据。

    GCP 客户端库使用称为 Application Default Credentials (ADC) 的策略来查找您的应用程序的凭据。

    默认情况下,客户端库将使用环境变量指向的 JSON。如果未找到 JSON,但您的应用正在 App Engine、Compute Engine 或 Kubernetes Engine 上运行,那么您的应用将使用默认服务帐户的凭据(例如,如果您的应用在应用引擎。)

    【讨论】:

    猜你喜欢
    • 2023-02-06
    • 2020-08-13
    • 1970-01-01
    • 2020-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-04
    相关资源
    最近更新 更多