Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/FieldDB/PraatTextGridJS
A small library which can parse TextGrid into json and json into TextGrid
https://github.com/FieldDB/PraatTextGridJS
Last synced: 3 months ago
JSON representation
A small library which can parse TextGrid into json and json into TextGrid
- Host: GitHub
- URL: https://github.com/FieldDB/PraatTextGridJS
- Owner: FieldDB
- License: apache-2.0
- Created: 2014-04-13T17:04:35.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2021-12-14T14:30:29.000Z (almost 3 years ago)
- Last Synced: 2024-05-08T23:44:05.480Z (6 months ago)
- Language: JavaScript
- Size: 179 KB
- Stars: 11
- Watchers: 3
- Forks: 5
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- low-resource-languages - PraatTextGridJS - A small library which can parse TextGrid into json and json into TextGrid. (Software / Utilities)
README
[![Build Status](https://travis-ci.org/OpenSourceFieldlinguistics/PraatTextGridJS.png)](https://travis-ci.org/OpenSourceFieldlinguistics/PraatTextGridJS)
# textgridA 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````javascript
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][min] or the [development version][max].[min]: https://raw.github.com/OpenSourceFieldlinguistics/PraatTextGridJS/master/dist/textgrid.min.js
[max]: https://raw.github.com/OpenSourceFieldlinguistics/PraatTextGridJS/master/dist/textgrid.jsIn your web app:
```html
var textgridAsJson = TextGrid.textgridToIGT(originalTextGridAsText);
```
In your code, you can attach textgrid's methods to any object.
```html
var exports = Bocoup.utils;
var textgridAsJson = Bocoup.utils.textgridToIGT(originalTextGridAsText); // "init"
```
An example of what you can do with the result.
```js
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](http://gruntjs.com/)._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.