Giter VIP home page Giter VIP logo

praattextgridjs's Introduction

Build Status

textgrid

A small library which can parse TextGrid into json and json into TextGrid

Getting Started

On the server

Install the module with: npm install textgrid --save

var textgrid = require('textgrid');
const fs = require('fs')

var sampleUtterancesTextGrid = fs.readFileSync('./test.TextGrid', {
  encoding: "UTF-8"
});
var json = textgrid.TextGrid.textgridToJSON(sampleUtterancesTextGrid)
console.log(json)

In the browser

Install the module with: bower install textgrid --save or,

Download the production version or the development version.

In your web app:

<script src="bower_components/textgrid/dist/textgrid.min.js"></script>
<script>
  var textgridAsJson = TextGrid.textgridToIGT(originalTextGridAsText);
</script>

In your code, you can attach textgrid's methods to any object.

<script>
var exports = Bocoup.utils;
</script>
<script src="bower_components/textgrid/dist/textgrid.min.js"></script>
<script>
var textgridAsJson = Bocoup.utils.textgridToIGT(originalTextGridAsText); // "init"
</script>

An example of what you can do with the result.

var textgrid = TextGrid.textgridToIGT(text);
if (textgrid.isIGTNestedOrAlignedOrBySpeaker.probablyAligned) {
	for (itemIndex in textgrid.intervalsByXmin) {
		if (!textgrid.intervalsByXmin.hasOwnProperty(itemIndex)) {
			continue;
		}
		if (textgrid.intervalsByXmin[itemIndex]) {
			row = {};
			for (intervalIndex = 0; intervalIndex < textgrid.intervalsByXmin[itemIndex].length; intervalIndex++) {
				interval = textgrid.intervalsByXmin[itemIndex][intervalIndex];
				row.startTime = row.startTime ? row.startTime : interval.xmin;
				row.endTime = row.endTime ? row.endTime : interval.xmax;
				row.utterance = row.utterance ? row.utterance : interval.text.trim();
				row.modality = "spoken";
				row.tier = interval.tierName;
				row.speakers = interval.speaker;
				row.audioFileName = interval.fileName || audioFileName;
				row.CheckedWithConsultant = interval.speaker;
				consultants.push(row.speakers);
				row[interval.tierName] = interval.text;
				header.push(interval.tierName);
			}
			matrix.push(row);
		}
	}
} else {
	for (itemIndex in textgrid.intervalsByXmin) {
		if (!textgrid.intervalsByXmin.hasOwnProperty(itemIndex)) {
			continue;
		}
		if (textgrid.intervalsByXmin[itemIndex]) {
			for (intervalIndex = 0; intervalIndex < textgrid.intervalsByXmin[itemIndex].length; intervalIndex++) {
				row = {};
				interval = textgrid.intervalsByXmin[itemIndex][intervalIndex];
				row.startTime = row.startTime ? row.startTime : interval.xmin;
				row.endTime = row.endTime ? row.endTime : interval.xmax;
				row.utterance = row.utterance ? row.utterance : interval.text.trim();
				row.modality = "spoken";
				row.tier = interval.tierName;
				row.speakers = interval.speaker;
				row.audioFileName = interval.fileName || audioFileName;
				row.CheckedWithConsultant = interval.speaker;
				consultants.push(row.speakers);
				row[interval.tierName] = interval.text;
				header.push(interval.tierName);
				matrix.push(row);
			}
		}
	}
}

Documentation

http://opensourcefieldlinguistics.github.io/FieldDB/

Examples

See tests directory for more ways to use the library

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

The "dist" subdirectory files are generated via Grunt. You'll find source code in the "lib" subdirectory!

Release History

  • v1.102.3 April 22 2014 Long audio import support
  • v2.2.0 April 22 2014 Support for multiple small files each corresponding to an utterance

License

Copyright (c) 2014 OpenSourceFieldLinguistics Contribs
Licensed under the Apache 2.0 license.

praattextgridjs's People

Contributors

cesine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.