0
using (var stream = new FileStream("C:/textToSpeech/client_secret.json", FileMode.Open, FileAccess.Read))
{
    var credential = GoogleCredential.FromStream(stream).CreateScoped(LoggingServiceV2Client.DefaultScopes);

    var channel = new Grpc.Core.Channel(
        LoggingServiceV2Client.DefaultEndpoint.ToString(),
        credential.ToChannelCredentials());

    var client = await TextToSpeechClient.CreateAsync(channel.ShutdownToken);

    //var client = TextToSpeechClient.Create();
    var input = new SynthesisInput
    {
        Text = "This is Demo of the Google Cloud Text-to-Speech API"
    };
    VoiceSelectionParams voiceSelection = new VoiceSelectionParams
    {
        LanguageCode = "en-US",
        SsmlGender = SsmlVoiceGender.Female,

    };
    var audioConfig = new AudioConfig
    {
        AudioEncoding = AudioEncoding.Mp3
    };

    var response = client.SynthesizeSpeech(input, voiceSelection, audioConfig);
    using (var output = File.Create("output.mp3"))
    {
        response.AudioContent.WriteTo(output);
    }

    Console.WriteLine("Audio content written to file output.mp3");
}

I want to convert my text to audio text in a form application but I get an error while translating. I signed up for Google Cloud Platform and created my JSON file by doing the necessary actions. I am getting the following error while authorizing the API.You can see the screenshot of the error I got here. I added the necessary things to the environment variables. I tried every solution I found on the internet, but I could not get rid of this error. Error => System.InvalidOperationException: 'Error creating credential from JSON. Unrecognized credential type .'

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
mia
  • 19
  • 3
  • Does this answer your question? [Loading Service account Json key file](https://stackoverflow.com/questions/35935432/loading-service-account-json-key-file) – Loathing Jun 30 '21 at 21:47
  • Or maybe https://stackoverflow.com/questions/44337136/how-do-i-create-a-googlecredential-from-an-authorized-access-token – Loathing Jun 30 '21 at 21:48
  • It looks like your JSON file isn't a valid service account key. Please include the structure **but none of the values, which are security sensitive** of the JSON file in the question. Also note that `GoogleCredential.FromFile` is a simpler way of loading a credential from a file. Additionally, you're not actually using your channel at the moment... you should use `TextToSpeechClientBuilder` to specify custom authentication, as per https://googleapis.github.io/google-cloud-dotnet/docs/faq.html#how-can-i-use-non-default-credentials-for-grpc-based-apis – Jon Skeet Jul 01 '21 at 06:55
  • It's also worth noting that the error has nothing to do with the Text-to-Speech API - given that your problem comes on the `credential` line, nothing after that is relevant to *this* specific problem. (It'll be relevant to later issues, of course.) It would be good to reduce the question to just the specific credential part, to tackle one problem at a time. – Jon Skeet Jul 01 '21 at 07:00
  • Could you managed to solve the issue? – Jordi Jul 02 '21 at 15:06
  • The problem is entirely related to the json file. I downloaded the json file again by following the documents where I will download it. Thank you everyone. – mia Jul 14 '21 at 11:17

0 Answers0