Skip to content

Instantly share code, notes, and snippets.

@anonrose
Created February 26, 2021 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonrose/01d9860bf7d6d75b8870acf8e57aa168 to your computer and use it in GitHub Desktop.
Save anonrose/01d9860bf7d6d75b8870acf8e57aa168 to your computer and use it in GitHub Desktop.
synthesize earnings call transcripts from GCP
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');
const puppeteer = require('puppeteer');
const auth = {
credentials: { // your gcp service account credentials
}
};
// seeking alpha earnings transcript, change for different transcript
const seekingAlphaURL = 'https://seekingalpha.com/article/4409236-root-root-ceo-alex-timm-on-q4-2020-results-earnings-call-transcript';
(async () => {
try {
const browser = await puppeteer.launch({
args: [
'--incognito',
],
headless: false
});
const page = await browser.newPage();
await page.goto(seekingAlphaURL, {
waitUntil: 'networkidle0',
});
await new Promise((res) => setTimeout(res, 2000))
page.setViewport({ width: 1200, height: 1600 })
await page.waitFor('[data-test-id="content-container"]');
let [text] = Object.values(await page.evaluate(() => ({ transcript: document.querySelector('[data-test-id="content-container"]').innerText })));
const segments = text.split('\n\n');
const client = new textToSpeech.TextToSpeechClient(auth);
const responses = await Promise.all(segments.map(text => {
const request = {
input: { text },
voice: { languageCode: 'en-US', ssmlGender: 'MALE' },
audioConfig: { audioEncoding: 'MP3' },
};
return client.synthesizeSpeech(request)
}));
const writeFile = util.promisify(fs.writeFile);
await writeFile('output.mp3', Buffer.concat(responses.map(([r]) => r.audioContent)), 'binary');
console.log('Audio content written to file: output.mp3');
await browser.close();
} catch (error) {
console.error(error)
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment