timmahrt / praatIO.js

Javascript library for reading and writing textgrid files
MIT License
15 stars 4 forks source link

parseTextgrid: Entries in entryList with empty Labels are not included. Maybe including interval number? #5

Closed CarlosJimenez closed 4 years ago

CarlosJimenez commented 4 years ago

Hi, I started to use praatIO in a project. It's really nice to handle TextGrids from javascript. In the TextGrid that I am using, I use empty labels, and they are not listed in parseTextgrid (short or Normal) We have emptyLabels to mark intervals in the TextGrid pending of posterior labelling I use interval number from Praat scripts to cut parts of the Sound. So interval number is important in my case.

In lines 137, 154, 237, 249, of textgrid_io.js you use

label = label.trim();
if (label === '') continue;

I don't know what lateral impacts could have to remove those lines.

Maybe a nice improvement could be adding interval number to entryList as a new element in the entry

entryList.push([parseFloat(timeStart), parseFloat(timeEnd), label, interval]);

Here you have my problematic TextGrid example.TextGrid.zip

If you are so kind to have a look in this issue, I could give you more info if you need it. Thank you very much for your work.

Best regards.

timmahrt commented 4 years ago

Hi Carlos, To make sure I understand, you are asking for two unrelated changes? 1) read in textgrids while preserving unlabeled intervals 2) associate an index with each entry

1 is a simple change that I have already implemented in my python praatio library.

I am less certain about 2. It seems simple enough to add but maintaining the index could be difficult. The information would be discarded when saving the textgrid right? Would it be difficult to find/maintain the index information yourself during runtime?

I should be able to implement 1 today or tomorrow. Thank you!

CarlosJimenez commented 4 years ago

Hi Tim Wow! You are so fast to answer. Thank you very much

To make sure I understand, you are asking for two unrelated changes?

I suggested 2 possible ways to solve the issue.

  1. Preserving unlabeled intervals (but could impact in searching and I don't know lateral effects)
  2. including the interval number as a associated index solves my issue

    I am less certain about 2. It seems simple enough to add but maintaining the index could be difficult. The information would be discarded when saving the textgrid right? Would it be difficult to find/maintain the index information yourself during runtime?

    The index is already in TextGrid at interval[x] (I am using the latest version of Praat, maybe in previous releases the TextGrid format was different)

    xmax = 3328.2349791666666 
    intervals: size = 83 
    intervals [1]:
        xmin = 0 
        xmax = 68.84705897920229 
        text = "" 
     intervals [2]:
        xmin = 68.84705897920229 
        xmax = 70.995053810749 
        text = "Burla2" 
    ....

I should be able to implement 1 today or tomorrow. Thank you!

Don't worry about suggestion 2. If you implement 1 I will be happy!!! You are awesome, Tim !!!!

Best regards

timmahrt commented 4 years ago

Hi Carlos, I've released a new version 2.3.0.

The function parseTextgrid now has the signature parseTextgrid(text, readRaw = false)

If readRaw is set to True, intervals and points with empty labels '' will not be removed from the input. Will that work for your case?

The latest version is on npm, so if you update, you should be able to get it. Please let me know if you have any questions or concerns!

Thanks! Tim

timmahrt commented 4 years ago

I left label = label.trim(); where it was originally. I don't think it affected your use case. But if you want, I can move it too.

CarlosJimenez commented 4 years ago

Hi Tim It works perfectly. Thank you very much for your help and time. Again, you are awesome!!!! Best regards