gpt4 book ai didi

node gTTS how to increase the speed of generated output(节点gTTS如何提高生成输出的速度)

转载 作者:bug小助手 更新时间:2023-10-25 23:51:16 31 4
gpt4 key购买 nike



I am using npm package https://www.npmjs.com/package/gtts to generate audio file based on input text provided. I wanted to increase the speed of generated output to 1.25 which I am unable to do. Required some assistance.

我正在使用NPM包https://www.npmjs.com/package/gtts来生成基于输入文本提供的音频文件。我希望将生成输出的速度提高到1.25,但我无法做到这一点。需要一些帮助。


Below is the code for reference:

下面是代码供参考:


const gTTS = require('gtts');

let speech = 'Welcome to GeeksforGeeks';
const gtts = new gTTS(speech, 'en');

gtts.save('Voice.mp3', function (err, result){
if(err) { throw new Error(err); }
console.log("Text to speech converted!");
});

I tried using say as well but I am unable to change the voice to a female voice. Here is the code for that as well.

我也试着用Say,但我无法将声音更改为女性声音。以下也是这方面的代码。


const say = require('say');
const { exec } = require('child_process');

const text = 'Welcome to GeeksforGeeks';
const speed = 2.0; // Adjust the speed (2.0 for double speed, 0.5 for half speed)

// Function to convert text to speech and save as WAV file
function textToSpeech(text, callback) {
say.export(text, null, speed, 'output.wav', callback);
}

// Function to adjust audio speed using soundstretch
function adjustAudioSpeed(inputFile, outputFile, speed, callback) {
const command = `soundstretch "${inputFile}" "${outputFile}" -tempo=${speed}`;
exec(command, callback);
}

// Usage
textToSpeech(text, function () {
console.log('Text to speech converted!');

const inputFileName = 'output.wav';
const outputFileName = 'output_adjusted.wav';

adjustAudioSpeed(inputFileName, outputFileName, speed, function (error, stdout, stderr) {
if (error) {
console.error('Error:', error);
} else {
console.log('Audio speed adjusted!');
}
});
});

更多回答
优秀答案推荐
更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com