<commit_before>const debug = require('debug')
const fs = require('fs-extra')
const path = require('path')
const GoogleClient = require('@google-cloud/text-to-speech').TextToSpeechClient

const GoogleProvider = function (opts) {
  try {
    this.instance = new GoogleClient({
      credentials: opts.email || opts.privateKey ? {
        client_email: opts.email,
        private_key: opts.privateKey
      } : undefined,
      keyFilename: opts.projectFile ? path.resolve(opts.projectFile) : undefined,
      projectId: opts.projectId
    })
  } catch (err) {
    this.instance = null
  }
}

exports.GoogleProvider = GoogleProvider

GoogleProvider.prototype.buildPart = function () {
  return {
    synthesizer: this.instance.synthesizeSpeech.bind(this.instance)
  }
}

/**
 * Calls the Google Cloud API with the given info.
 */
GoogleProvider.prototype.generate = (info, i, callback) => {
  info.task.title = info.task.title.replace(/\d+\//, `${i}/`)

  const request = {
    input: info.opts.type === 'ssml'
      ? { ssml: info.text }
      : { text: info.text },
    voice: {
      languageCode: info.opts.language,
      name: info.opts.voice
    },
    audioConfig: {
      audioEncoding: info.opts.format === 'pcm' ? 'LINEAR16'
        : info.opts.format === 'ogg' ? 'OGG_OPUS' : 'MP3',
      sampleRateHertz: info.opts.sampleRate
        ? parseInt(info.opts.sampleRate, 10)
        : undefined
    }
  }

  debug('generate')('Making request to Google Cloud Platform')
  info.synthesizer(request, (err, response) => {
    if (err) {
      debug('generate')(`Error during request: ${err.message}`)
      return callback(err)
    }

    debug('generate')(`Writing audio content to ${info.tempfile}`)<commit_msg>fix(gcp): Turn off retries<commit_after>const debug = require('debug')
const fs = require('fs-extra')
const path = require('path')
const GoogleClient = require('@google-cloud/text-to-speech').TextToSpeechClient

const GoogleProvider = function (opts) {
  try {
    this.instance = new GoogleClient({
      credentials: opts.email || opts.privateKey ? {
        client_email: opts.email,
        private_key: opts.privateKey
      } : undefined,
      keyFilename: opts.projectFile ? path.resolve(opts.projectFile) : undefined,
      projectId: opts.projectId
    })
  } catch (err) {
    this.instance = null
  }
}

exports.GoogleProvider = GoogleProvider

GoogleProvider.prototype.buildPart = function () {
  return {
    synthesizer: this.instance.synthesizeSpeech.bind(this.instance)
  }
}

/**
 * Calls the Google Cloud API with the given info.
 */
GoogleProvider.prototype.generate = (info, i, callback) => {
  info.task.title = info.task.title.replace(/\d+\//, `${i}/`)

  const request = {
    input: info.opts.type === 'ssml'
      ? { ssml: info.text }
      : { text: info.text },
    voice: {
      languageCode: info.opts.language,
      name: info.opts.voice
    },
    audioConfig: {
      audioEncoding: info.opts.format === 'pcm' ? 'LINEAR16'
        : info.opts.format === 'ogg' ? 'OGG_OPUS' : 'MP3',
      sampleRateHertz: info.opts.sampleRate
        ? parseInt(info.opts.sampleRate, 10)
        : undefined
    }
  }
  const opts = {
    retry: null
  }

  debug('generate')('Making request to Google Cloud Platform')
  info.synthesizer(request, opts, (err, response) => {
    if (err) {
      debug('generate')(`Error during request: ${err.message}`)
      return callback(err)
    }

    debug('generate')(`Writing audio content to ${info.tempfile}`)
{'fraction_non_alphanumeric': 0.14621559633027523, 'fraction_numerical': 0.0028669724770642203, 'mean_word_length': 3.0759345794392523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5284244', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1091, 'n_words': 229}