From 9f00d57a00de7ef72ff2bd5f71d7e1f76c5fbc12 Mon Sep 17 00:00:00 2001 From: Wuriko Date: Sun, 6 Oct 2024 11:55:01 +0200 Subject: [PATCH] chore: remove logs --- examples/custom-engine-api/index.js | 143 ++++++++++++++-------------- 1 file changed, 70 insertions(+), 73 deletions(-) diff --git a/examples/custom-engine-api/index.js b/examples/custom-engine-api/index.js index 6f35dc27..4216768a 100644 --- a/examples/custom-engine-api/index.js +++ b/examples/custom-engine-api/index.js @@ -1,6 +1,5 @@ const express = require('express') const app = express() -const port = 3000 const pkg = require('./package.json') const say = require('say') const cors = require('cors') @@ -14,85 +13,83 @@ const ENDPOINT_PORT = 3000 app.use(cors()) app.use(bodyParser.json()) -app.use(bodyParser.urlencoded({ extended: true })) +app.use(bodyParser.urlencoded({extended: true})) app.post('/list-voices', async (req, res) => { - try { - const { - body: { - credentials: { - apiKey, // API key provided by the user if required - }, - }, - } = req - console.log(req.body) - const voices = await new Promise((resolve, reject) => { - say.getInstalledVoices((err, voices) => { - if (err) return reject(err) - return resolve(voices) - }) - }) - res.status(200).json( - voices.map((name) => ({ - id: name, // id must be unique - name, // name of the voice - category: 'Say', // category of the voice - languageCode: 'en-US', // language code of the voice - })), - ) - } catch (err) { - res.status(500).json({ error: err.message }) - } + try { + const { + body: { + credentials: { + apiKey, // API key provided by the user if required + }, + }, + } = req + const voices = await new Promise((resolve, reject) => { + say.getInstalledVoices((err, voices) => { + if (err) return reject(err) + return resolve(voices) + }) + }) + res.status(200).json( + voices.map((name) => ({ + id: name, // id must be unique + name, // name of the voice + category: 'Say', // category of the voice + languageCode: 'en-US', // language code of the voice + })), + ) + } catch (err) { + res.status(500).json({error: err.message}) + } }) app.post('/synthesize-speech', async (req, res) => { - try { - const { - body: { - credentials: { - apiKey, // API key provided by the user if required - }, - payload: { - text, // message to be spoken - voice: { - id, // id must be unique - name, // name of the voice - category, // category of the voice - languageCode, // language code of the voice - }, - }, - }, - } = req - console.log(req.body) - const outputFile = path.join(__dirname, 'example.mp3') - fs.mkdirSync(path.parse(outputFile).dir, { recursive: true }) - fs.writeFileSync(outputFile, '') + try { + const { + body: { + credentials: { + apiKey, // API key provided by the user if required + }, + payload: { + text, // message to be spoken + voice: { + id, // id must be unique + name, // name of the voice + category, // category of the voice + languageCode, // language code of the voice + }, + }, + }, + } = req + const outputFile = path.join(__dirname, 'example.mp3') + fs.mkdirSync(path.parse(outputFile).dir, {recursive: true}) + fs.writeFileSync(outputFile, '') - await new Promise((resolve, reject) => { - say.export(text, name, 1, outputFile, (err) => { - if (err) { - reject(err) - } - resolve(true) - }) - }) + await new Promise((resolve, reject) => { + say.export(text, name, 1, outputFile, (err) => { + if (err) { + reject(err) + } + resolve(true) + }) + }) - res.writeHead(200, { - 'Content-Type': 'audio/mp3', - }) - const stream = fs.createReadStream(outputFile).pipe(res) - stream.on('finish', () => { - fs.unlinkSync(outputFile) - }) - } catch (err) { - res.status(500).json({ error: err.message }) - } + res.writeHead(200, { + 'Content-Type': 'audio/mp3', + }) + const stream = fs.createReadStream(outputFile).pipe(res) + stream.on('finish', () => { + fs.unlinkSync(outputFile) + }) + } catch (err) { + res.status(500).json({error: err.message}) + } }) -app.listen(port, () => { - console.log( - `[${pkg.name}] API endpoint: ${ENDPOINT_BASE_URL}${ - ENDPOINT_PORT ? `:${ENDPOINT_PORT}` : '' - }`, - ) +app.listen(ENDPOINT_PORT, () => { + console.log( + `[${pkg.name}] API endpoint: ${ENDPOINT_BASE_URL}${ + ENDPOINT_PORT ? `:${ENDPOINT_PORT}` : '' + }`, + ) })