npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

praat-script

v0.4.2

Published

Generate and run Praat scripts from Node.js.

Downloads

20

Readme

praat-script

Generate and run Praat scripts from Node.js.

Installation

Download node at nodejs.org and install it, if you haven't already.

npm install praat-script --save

To actually run scripts, you will need Praat. node-praat (npm install praat) is one easy way to install it in a Node application. praat is an optional dependency of praat-script and is required for the .run() convenience method to function correctly.

Usage

Creating and running scripts

To demonstrate praat-script, we'll use a simple script that generates a Sound object, plays it and exits.

var praatScript = require('praat-script');
praatScript([
  'Create Sound as pure tone: "tone", 1, 0, 0.1, 44100, 440, 0.2, 0.01, 0.01' + '\r\n' +
  'Play'
]).run(function(err) {
    if (err)
        throw err;
    console.log('Success!');
});

But this module really shines when used along with ES6 tagged template strings.

Since template strings are multi-line, the ES6 version of our static script is already nicer to look at: (Run with a JavaScript engine that supports ES6 template strings, or use a transpiler like Traceur.)

praatScript`
  Create Sound as pure tone: "tone", 1, 0, 0.1, 44100, 440, 0.2, 0.01, 0.01
  Play
` //.run(...);

And now we can even embed JavaScript expressions directly in our Praat code! praat-script quotes and escapes everything correctly.

var freq = 440;
var name = "theTone";
praatScript`
  Create Sound as pure tone: ${name}, 1, 0, 0.1, 44100, ${freq * 2}, 0.2, 0.01, 0.01
  Play
` //.run(...);

Of course, since template strings are merely syntactic sugar, you can technically also do the same in ES5, though it won't be as readable:

praatScript(
    [
        'Create Sound as pure tone: ',
        /* name will go here */ ', 1, 0, 0.1, 44100, ',
        /* freq*2 will go here */ ', 0.2, 0.01, 0.01' + '\r\n' +
        'Play'
    ],
    name, freq*2
) //.run(...);

Miscellaneous functions

Getting the text of a script

praatScript`...` .toString() or praatScript([...]).toString() works as you'd expect.

Specifying the path to Praat

Using .runWith('path/to/praat', callback) instead of .run(callback) will use the specified Praat executable instead of the default (which is the path returned by require('praat')).

.formatArgument(value)

praatScript.formatArgument(value) takes a JavaScript value and returns a string formatted for use in Praat.

.run(script, cb) (and .runWith(pathToPraat, script, cb))

You can bypass the template functionality entirely and execute a script by passing its source code as praatScript.run()'s first argument (a string). This otherwise works similarly to calling .run() on the template string instance.

Tests

npm install
npm test

> [email protected] test node-praat-script
> mocha
  praat-script module
    #formatArgument()
      √ should quote and escape string arguments 
      √ should stringify numbers 
      √ should convert booleans to 0 and 1 
    template string
      √ should escape arguments correctly via praatScript`...` 
    #run()
      √ should run an empty script successfully (118ms)
      √ should run a simple script successfully (872ms)
      √ should run a template string script successfully (1052ms)
  template script instance
    #run()
      √ should run an empty script successfully (82ms)
      √ should run a simple script successfully (950ms)
      √ should run a template string script successfully (897ms)
  10 passing (4s)

Dependencies

  • tmp: Temporary file and directory creator

Optional Dependencies

  • praat: A cross-platform NPM installer for Praat (required to use .run())

Dev Dependencies

  • mocha: simple, flexible, fun test framework
  • mocha-traceur: A "compiler" plugin for Mocha that makes non-dependency JS files to pass through Traceur
  • traceur: ES6 to ES5 compiler

License

MIT

Generated by package-json-to-readme