benchmark-synthesis.js
A script used to benchmark the synthesis runnin on https://abair.ie/api2/.
import autocannon from "autocannon"
import fastify from "fastify"
const url1 = 'https://abair.ie/api2/synthesise?voice=ga_MU_nnc_nemo&input=N%C3%ADl%20aon%20strains%C3%A9ir%C3%AD%20againn%20le%20gr%C3%A1T%C3%A1%20na%20rialacha%20ar%20eolas%20agat%20agus%20mise&audioEncoding=MP3&cutSilence=true&speed=1.0&ps=0.0&pa=1.0';
const url2 = 'https://synthesis.abair.ie/nemo/synthesise?voice=nnc.nemo&input=N%C3%ADl%20aon%20strains%C3%A9ir%C3%AD%20againn%20le%20gr%C3%A1T%C3%A1%20na%20rialacha%20ar%20eolas%20agat%20agus%20mise&audioEncoding=MP3&cutSilence=true&speed=1.0&ps=0.0&pa=1.0';
const a = {
baseUrl: "https://abair.ie/api2/synthesise",
voice: "ga_MU_nnc_nemo"
}
const b = {
baseUrl: "https://synthesis.abair.ie/nemo",
voice: "nnc.nemo"
}
const baseText = `Is dalta mé. Déanaim staidéar ar eolaíocht ríomhaireachta. Oibrím ar theicneolaíocht urlabhra don Ghaeilge. Braithim go bhfuil an obair seo an-suimiúil. Rugadh mé sa bhliain %year%. Ní dóigh liom go bhfuil an abairt tástála seo an-mhaith, ach is fada a fheiceáil an bhfuil tábhacht ag baint le fad na cainte. `
const setupRequest = (context) => (req) => {
const year = getRandomNumber(1930, 2023);
const input = encodeURIComponent(baseText + year);
const voice = encodeURIComponent(context.voice);
const query = `?input=${input}&voice=${voice}&outputType=JSON`
req.path += query;
return req;
};
async function benchmark(context) {
const result = await autocannon({
url: context.baseUrl,
connections: 10, // Number of concurrent connections
duration: 10, // Duration of the test in seconds
setupRequest: setupRequest(context)
});
console.log(result);
autocannon.printResult(result);
// result.
// console.log(`Results for ${context.baseUrl}:`);
// console.log('Avg Requests/sec:', result.requests.average);
// console.log('Avg Latency (ms):', result.latency.average);
// console.log('-----------------------------------');
}
// Promise.all([benchmark(a), benchmark(b)]).then(() => console.log('All benchmarks completed.'));
const year = getRandomNumber(1930, 2023);
const input = encodeURIComponent("Dia dhuit " + year);
const voice = encodeURIComponent(b.voice);
const query = `?input=${input}&voice=${voice}&outputType=JSON`
console.log(b.baseUrl + query);
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
package.json
This JSON file contains dependencies used by the benchmark-synthesis.js script.
{
"name": "benchmarks",
"version": "1.0.0",
"description": "",
"main": "benchmark-synthesis.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"type": "module",
"author": "",
"license": "ISC",
"dependencies": {
"autocannon": "^7.11.0"
}
}