-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathref.txt
More file actions
36 lines (30 loc) · 954 Bytes
/
Copy pathref.txt
File metadata and controls
36 lines (30 loc) · 954 Bytes
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
const express = require("express")
const app = express()
const port = 4000
const gtts = require("node-gtts")("en-uk")
const path = require("path")
const puppeteer = require("puppeteer")
const cors = require("cors")
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(cors())
const TextToSpeech = async (url, name) => {
const filepath = path.join(__dirname, `${name}.mp3`)
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto(url)
const content = await page.$eval("*", (el) => el.innerText)
const strippedContent = content.replace(/\s+/g, " ").trim()
gtts.save(filepath, strippedContent, function() {
console.log("Audio Downloaded")
})
await browser.close()
}
app.post("/get_text", async (req, res) => {
let { url, name } = req.body
TextToSpeech(url, name)
})
app.listen(port, () => {
console.log(`Listening at http://localhost:${port}`)
})
"react-scripts": "4.0.3",