-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
65 lines (52 loc) · 1.76 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'dotenv/config'
import fs from 'fs'
import path from 'path'
import { oraPromise } from 'ora'
import PodcastCreator from './src/PodcastCreator.js'
import PodcastRecorder from './src/PodcastRecorder.js'
import HackerNews from './src/HackerNews.js'
import { fileURLToPath } from 'url'
if (!process.env.OPENAI_API_KEY) {
console.error(
'OPENAI_API_KEY is not set. Please set the environment variable.'
)
process.exit(1)
}
const creator = new PodcastCreator()
const recorder = new PodcastRecorder()
const topStoryIds = await oraPromise(
HackerNews.fetchTopStories(),
'Getting top stories from HackerNews'
)
const summaries = []
for (const id of topStoryIds) {
const story = await HackerNews.fetchStory(id)
const text = await creator.getWebPageText(story.url)
if (text !== '') {
const summary = await oraPromise(
creator.generateSummary(text),
`Summarizing '${story.title}'`
)
summaries.push(`Title: ${story.title}\n\nSummary: ${summary}`)
}
}
const podcast = await oraPromise(
creator.generatePodcast(summaries),
'Generating podcast from summaries'
)
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const outputFolder = path.join(__dirname, 'output')
const localDate = new Date()
localDate.setMinutes(localDate.getMinutes() - localDate.getTimezoneOffset())
const dateStr = localDate.toISOString().slice(0, 10)
const outputFilename = `${dateStr}_podcast.mp3`
const transcriptionFilename = `${dateStr}_transcription.txt`
const transcriptionFilePath = path.join(outputFolder, transcriptionFilename)
await oraPromise(
fs.promises.writeFile(transcriptionFilePath, podcast),
'Writing transcript to disk'
)
await oraPromise(
recorder.createRecording(podcast, path.join(outputFolder, outputFilename)),
'Creating recording'
)