alphablender
alphablender

Reputation: 2238

Modify this node.js code to output .wav instead of .mp4?

I'm trying to modify the following code to output .wav instead of .mp4:

node-tts text to speech synthsizer, (OS X)

The issue is, I'm not a node.js developer and have no idea how to make the change, and if it is even possible. I'm attempting to speechify an app so that visually impaired users can use it if they are running the TTS server on their LAN. I need .wav output for my project.

Can anyone tell me if this is possible and if so, point out where in the code the audio file is actually generated? Presumably this code uses the Mac's built in speech synthesizer to create an audio file and this code just delivers it to the calling client.

Note that this server can deliver audio via the built in speakers on the mac or as a response to a Restful API request. I'm only interested in getting the actual audio file as a .wav via the Rest API.

Upvotes: 0

Views: 466

Answers (2)

Alexander O'Mara
Alexander O'Mara

Reputation: 60527

The code you are looking for is in the generate method of lib/ttsapi.js. Here is an excerpt from the method.

var $this = this,
    command  = '/usr/bin/say',
    options = {
        "cwd": "/tmp/",
        "env": {
            "ENV":"development"
        },
        "customFds":[-1, -1, -1]
    },
    args = [
        '-o', filename,
        '-v', voice,
        text
    ],
    output = '';

if (debug) util.log('|tts|generating|voice='+voice+'|format='+this.format+'|text='+text);
var child = spawn(command, args, options);

Here we can see it is using the built-in say command-line utility on OS X, which is located under /usr/bin/say. It should be possible to modify the arguments to produce a WAV file, but is a bit tricky. For whatever reason, contrary to what the documentation on the say command suggests, specifying --file-format=WAVE produces the following error.

Looking up file extensions for type failed: typ?

This can be worked around using the --data-format argument however. You will need to modify the code to execute a command like the following.

say -o "testing123.wav" --data-format=LEF32@22050 "testing 123"

Upvotes: 1

user149341
user149341

Reputation:

The core of that server is, indeed, just calling /usr/bin/say. It doesn't look like that command supports output as .wav files, but it does support a number of other formats; try:

say "Hello world" -o hello.aiff

See man say for more details.

Upvotes: 1

Related Questions