Authenticate Google Cloud

Hello, I’m trying to authenticate google cloud to use speech to text.
I get this error

ERROR: [Error: ENOENT: no such file or directory, open '/var/task/auths.google_cloud.oauth_access_token'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/var/task/auths.google_cloud.oauth_access_token'
}

I have uploaded auth key in pipedream auth section.

It seems like Google needs a file and Pipedream provides only the API Key (as long as I’m concerned). You can use axios in order to make a post request to google cloud instead.

@ivnxyz I solved authentication part - in pipedream there is an option to add authentication step with Google Cloud and then use Node.js step with Google Cloud.
Now I’m trying to get a basic transcription request to work - it doesn’t work :slight_smile:

// Required workaround to get the @google-cloud/storage package
// working correctly on Pipedream
require("@dylburger/umask")()

const { Storage } = require('@google-cloud/storage')

const key = JSON.parse(auths.google_cloud.key_json)
 
// Creates a client from a Google service account key.
// See https://cloud.google.com/nodejs/docs/reference/storage/1.6.x/global#ClientConfig
const storage = new Storage({
  projectId: key.project_id,
  credentials: {
    client_email: key.client_email,
    private_key: key.private_key,
  }
})

// Uncomment this section and rename for your bucket before running this code
//const bucketName = 'mrhackio2';

//await storage.createBucket(bucketName)
//console.log(`Bucket ${bucketName} created.`)

/*const results = await storage.getBuckets();

    const [buckets] = results;

    console.log('Buckets:');
    buckets.forEach(bucket => {
      console.log(bucket.name);
    });

*/
  

// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');

// Creates a client
const client = new speech.SpeechClient();

async function quickstart() {
  // The path to the remote LINEAR16 file
  const gcsUri = 'gs://mrhackio/audio-files/test-recording.mp3';

  // The audio file's encoding, sample rate in hertz, and BCP-47 language code
  const audio = {
    uri: gcsUri,
  };
  const config = {
    encoding: 'LINEAR16',
    sampleRateHertz: 16000,
    languageCode: 'en-US',
  };
  const request = {
    audio: audio,
    config: config,
  };

  // Detects speech in the audio file
  const [response] = await client.recognize(request);
  const transcription = response.results
    .map(result => result.alternatives[0].transcript)
    .join('\n');
  console.log(`Transcription: ${transcription}`);
}
quickstart();