timmahrt / praatIO

A python library for working with praat, textgrids, time aligned audio transcripts, and audio files. It is primarily used for extracting features from and making manipulations on audio files given hierarchical time-aligned transcriptions (utterance > word > syllable > phone, etc).
MIT License
310 stars 33 forks source link

Creating textgrid with data #9

Closed Terrance82 closed 5 years ago

Terrance82 commented 5 years ago

Hi, I'm new to praat and after following your tutorial I've created a Textgrid that looks like this:

bobby.TextGrid File type = "ooTextFile short" Object class = "TextGrid"

0.0 1.194625

1 "IntervalTier" "phoneme" 0.0 1.194625 1 0.0 1.194625 "" However when I tried to print out data from my textgrid it doesn't work. When I use bobby_phone.TextGrid for example it works. My question is do you need the praat.exe to do it manually? Bobby_phone.Textgrid: File type = "ooTextFile" Object class = "TextGrid" xmin = 0.0 xmax = 1.194625 tiers? size = 1 item []: item [1]: class = "IntervalTier" name = "phone" xmin = 0.0 xmax = 1.18979591837 intervals: size = 15 intervals [1]: xmin = 0.0124716553288 xmax = 0.06469123242311078 text = "" intervals [2]: xmin = 0.06469123242311078 xmax = 0.08438971390281873 text = "B" intervals [3]: xmin = 0.08438971390281873 xmax = 0.23285789838876556 text = "AA1" intervals [4]: xmin = 0.23285789838876556 xmax = 0.2788210218414174 text = "B" intervals [5]: xmin = 0.2788210218414174 xmax = 0.41156462585 text = "IY0" intervals [6]: xmin = 0.41156462585 xmax = 0.47094510353588265 text = "R" intervals [7]: xmin = 0.47094510353588265 xmax = 0.521315192744 text = "IH1" intervals [8]: xmin = 0.521315192744 xmax = 0.658052967538796 text = "PT" intervals [9]: xmin = 0.658052967538796 xmax = 0.680952380952 text = "DH" intervals [10]: xmin = 0.680952380952 xmax = 0.740816326531 text = "AH0" intervals [11]: xmin = 0.740816326531 xmax = 0.807647261005538 text = "L" intervals [12]: xmin = 0.807647261005538 xmax = 0.910430839002 text = "EH1" intervals [13]: xmin = 0.910430839002 xmax = 0.980272108844 text = "JH" intervals [14]: xmin = 0.980272108844 xmax = 1.1171482864527198 text = "ER0" intervals [15]: xmin = 1.1171482864527198 xmax = 1.18979591837 text = ""
timmahrt commented 5 years ago

Hi Terrance, To create textgrids and manipulate textgrids in praatio, you dont need praat.exe. And the textgrids generated in praatio shouldn't be throwing away data. I'm not sure why your new textgrid is empty.

What data are you trying to print out?

Can you share your code and/or the generated textgrids (as files)? I'm not at my computer now but I can look at this in more detail later today.

On Tue, Jan 8, 2019, 10:37 Terrance82 <notifications@github.com wrote:

Hi, I'm new to praat and after following your tutorial I've created a Textgrid that looks like this:

bobby.TextGrid File type = "ooTextFile short" Object class = "TextGrid"

0.0 1.194625

1 "IntervalTier" "phoneme" 0.0 1.194625 1 0.0 1.194625 ""

However when I tried to print out data from my textgrid it doesn't work. When I use bobby_phone.TextGrid for example it works. My question is do you need the praat.exe to do it manually?

Bobby_phone.Textgrid: File type = "ooTextFile" Object class = "TextGrid"

xmin = 0.0 xmax = 1.194625 tiers? size = 1 item []: item [1]: class = "IntervalTier" name = "phone" xmin = 0.0 xmax = 1.18979591837 intervals: size = 15 intervals [1]: xmin = 0.0124716553288 xmax = 0.06469123242311078 text = "" intervals [2]: xmin = 0.06469123242311078 xmax = 0.08438971390281873 text = "B" intervals [3]: xmin = 0.08438971390281873 xmax = 0.23285789838876556 text = "AA1" intervals [4]: xmin = 0.23285789838876556 xmax = 0.2788210218414174 text = "B" intervals [5]: xmin = 0.2788210218414174 xmax = 0.41156462585 text = "IY0" intervals [6]: xmin = 0.41156462585 xmax = 0.47094510353588265 text = "R" intervals [7]: xmin = 0.47094510353588265 xmax = 0.521315192744 text = "IH1" intervals [8]: xmin = 0.521315192744 xmax = 0.658052967538796 text = "PT" intervals [9]: xmin = 0.658052967538796 xmax = 0.680952380952 text = "DH" intervals [10]: xmin = 0.680952380952 xmax = 0.740816326531 text = "AH0" intervals [11]: xmin = 0.740816326531 xmax = 0.807647261005538 text = "L" intervals [12]: xmin = 0.807647261005538 xmax = 0.910430839002 text = "EH1" intervals [13]: xmin = 0.910430839002 xmax = 0.980272108844 text = "JH" intervals [14]: xmin = 0.980272108844 xmax = 1.1171482864527198 text = "ER0" intervals [15]: xmin = 1.1171482864527198 xmax = 1.18979591837 text = ""

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/timmahrt/praatIO/issues/9, or mute the thread https://github.com/notifications/unsubscribe-auth/AChv0AgxzW5IeW3bMOjLnOOsz-niQwoqks5vA_ZygaJpZM4Z0nJY .

Terrance82 commented 5 years ago

**Hi tim,

This is my code for saving the textgrid as per documentation tutorial:**

import os from os.path import join

from praatio import tgio

inputPath = join('C:/Users/praatIO-master/praatIO-master', 'examples', 'files') outputPath = join(inputPath, "generated_textgrids")

if not os.path.exists(outputPath): os.mkdir(outputPath)

for fn in os.listdir(inputPath): name, ext = os.path.splitext(fn) if ext != ".wav": continue

wordTier = tgio.IntervalTier('phone', [], 0, pairedWav=join(inputPath, fn))

tg = tgio.Textgrid()
tg.addTier(wordTier)
tg.save(join(outputPath, name + ".TextGrid"))

for fn in os.listdir(outputPath): ext = os.path.splitext(fn)[1] if ext != ".TextGrid": continue print(fn)

And for now I'm trying to print the phone tier that I've created. Then I tried to print out the phone text but is empty so I tried using the bobby_phones.TextGrid and it give me the result: ['phone'] <praatio.tgio.IntervalTier object at 0x00000252192EFB00> ['B', 'AA1', 'B', 'IY0', 'R', 'IH1', 'PT', 'DH', 'AH0', 'L', 'EH1', 'JH', 'ER0']

Code for printing it out: inputFN = join('C:/Users/praatIO-master/praatIO-master', 'examples', 'files', 'bobby_phones.TextGrid')

tg = tgio.openTextgrid(inputFN) # Give it a file name, get back a Textgrid object print(tg.tierNameList)

firstTier = tg.tierDict[tg.tierNameList[0]]

phone = tg.tierDict['phone'] print(firstTier)

labelList = [entry[2] for entry in phone.entryList] print(labelList)

timmahrt commented 5 years ago

Oh, I think I understand now. You have an audio file that you want to auto annotate?

Unfortunately, praatio cannot do this. If you have an existing textgrid that you want to query or programmatically manipulate or if you want to generate textgrid templates to be hand modified, praatio can help with these tasks.

If you have text transcripts, you can use a forced aligner to estimate the phone locations. It uses speech recognition techniques to do so. The prosodylab-aligner and sppas are two systems that I have used in the past and can recommend. (SPPAS is easier to start using).

For forced alignment, you'll probably have to manually clean the result. The cleaner your recordings are the better.

If you do not have transcripts, you'll need to use a speech recognition engine to guess the input words. I don't have any experience with that though.

If you have questions or whatever, just let me know. I'm sorry for the confusion!

On Tue, Jan 8, 2019, 12:06 Terrance82 <notifications@github.com wrote:

Hi tim,

This is my code for saving the textgrid as per documentation tutorial:

import os from os.path import join

from praatio import tgio

inputPath = join('C:/Users/praatIO-master/praatIO-master', 'examples', 'files') outputPath = join(inputPath, "generated_textgrids")

if not os.path.exists(outputPath): os.mkdir(outputPath)

for fn in os.listdir(inputPath): name, ext = os.path.splitext(fn) if ext != ".wav": continue

wordTier = tgio.IntervalTier('phone', [], 0, pairedWav=join(inputPath, fn))

tg = tgio.Textgrid() tg.addTier(wordTier) tg.save(join(outputPath, name + ".TextGrid"))

for fn in os.listdir(outputPath): ext = os.path.splitext(fn)[1] if ext != ".TextGrid": continue print(fn)

And for now I'm trying to print the phone tier that I've created. Then I tried to print out the phone text but is empty so I tried using the bobby_phones.TextGrid and it give me the result: ['phone'] <praatio.tgio.IntervalTier object at 0x00000252192EFB00> ['B', 'AA1', 'B', 'IY0', 'R', 'IH1', 'PT', 'DH', 'AH0', 'L', 'EH1', 'JH', 'ER0']

Code for printing it out: inputFN = join('C:/Users/praatIO-master/praatIO-master', 'examples', 'files', 'bobby_phones.TextGrid')

tg = tgio.openTextgrid(inputFN) # Give it a file name, get back a Textgrid object print(tg.tierNameList)

firstTier = tg.tierDict[tg.tierNameList[0]]

phone = tg.tierDict['phone'] print(firstTier)

labelList = [entry[2] for entry in phone.entryList] print(labelList)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/timmahrt/praatIO/issues/9#issuecomment-452159547, or mute the thread https://github.com/notifications/unsubscribe-auth/AChv0NP9YyvgIN80hB1mlFBtRMtltEg-ks5vBAtSgaJpZM4Z0nJY .

Terrance82 commented 5 years ago

I see, so your bobby_phone.TextGrid is also uses text transcripts where you forced aligned it?

Also, if I have a totally different text transcript and I try to force aligned it on bobby.wav would it still work?

timmahrt commented 5 years ago

It's possible that it was force aligned but I've also done a lot of manual annotation. If you've never done significant manual phonetic annotation before, I've found it very educational--although not practical for large corpora.

Force alignment "forces" the timing of a phonetic spellout. If the actual recording does not correspond to the recording, the force alignment may fail. If it succeeds, it may be meaningless.

If your recordings are similar enough in content and structure, it could be ok--eg your sentences are all like CVCV VC the CVNCv: Mary ate the candy. Bobby ate the candy, etc.

If your utterences differ in the number of words or syllables, its not going to work.

Also, if there are speech errors, strongly accented speech, or non standard dialects in the recording, the forced aligner will make errors.

On Tue, Jan 8, 2019, 15:19 Terrance82 <notifications@github.com wrote:

I see, so your bobby_phone.TextGrid is also uses text transcripts where you forced aligned it?

Also, if I have a totally different text transcript and I try to force aligned it on bobby.wav would it still work?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/timmahrt/praatIO/issues/9#issuecomment-452188388, or mute the thread https://github.com/notifications/unsubscribe-auth/AChv0DrSp_wsFZddq0LEYSoYARTswEZ8ks5vBDhsgaJpZM4Z0nJY .

timmahrt commented 5 years ago

If you're working with English AND you want the phones to be populated into a textgrid so that an editor can slide the phones into their correct position, check out naiveWordAlignment in my pysle library: https://github.com/timmahrt/pysle/blob/master/pysle/praattools.py

If you have the location of the words and not the phones you can similarly use praattools.syllabifyTextgrid to get naive forced phone alignment.

The phone alignments are totally wrong, but can make the life of an editor easier if forced alignment is not possible.

On Tue, Jan 8, 2019, 16:20 Tim Mahrt <timmahrt@gmail.com wrote:

It's possible that it was force aligned but I've also done a lot of manual annotation. If you've never done significant manual phonetic annotation before, I've found it very educational--although not practical for large corpora.

Force alignment "forces" the timing of a phonetic spellout. If the actual recording does not correspond to the recording, the force alignment may fail. If it succeeds, it may be meaningless.

If your recordings are similar enough in content and structure, it could be ok--eg your sentences are all like CVCV VC the CVNCv: Mary ate the candy. Bobby ate the candy, etc.

If your utterences differ in the number of words or syllables, its not going to work.

Also, if there are speech errors, strongly accented speech, or non standard dialects in the recording, the forced aligner will make errors.

On Tue, Jan 8, 2019, 15:19 Terrance82 <notifications@github.com wrote:

I see, so your bobby_phone.TextGrid is also uses text transcripts where you forced aligned it?

Also, if I have a totally different text transcript and I try to force aligned it on bobby.wav would it still work?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/timmahrt/praatIO/issues/9#issuecomment-452188388, or mute the thread https://github.com/notifications/unsubscribe-auth/AChv0DrSp_wsFZddq0LEYSoYARTswEZ8ks5vBDhsgaJpZM4Z0nJY .

Terrance82 commented 5 years ago

okay! thanks for your explanation!