简体   繁体   English

使用Praat或任何其他音频处理工具从textGrid创建文本文件

[英]create text file from textGrid using Praat or any other audio processing tool

I have a textGrid file generated by Prosodylab-Aligner which I can open in Praat . 我有一个Prosodylab -Aligner生成的textGrid文件,可以在Praat打开。 Is there any possibility to get out of it a text file that looks like that: 是否有可能摆脱这样的文本文件:

Word in text | Pronounciation started at
Hello          0:0:0.000
my             0:0:1.125
friends        0:0:2.750

EDIT 编辑

Attached textGrid file: 附加的textGrid文件:

File type = "ooTextFile"
Object class = "TextGrid"

xmin = 0.0
xmax = 2.53
tiers? <exists>
size = 2
item []:
    item [1]:
        class = "IntervalTier"
        name = "phones"
        xmin = 0.0
        xmax = 2.53
        intervals: size = 13
            intervals [1]:
                xmin = 0.0
                xmax = 0.62
                text = "sil"
            intervals [2]:
                xmin = 0.62
                xmax = 0.78
                text = "K"
            intervals [3]:
                xmin = 0.78
                xmax = 0.81
                text = "L"
            intervals [4]:
                xmin = 0.81
                xmax = 0.92
                text = "IH1"
            intervals [5]:
                xmin = 0.92
                xmax = 1.02
                text = "K"
            intervals [6]:
                xmin = 1.02
                xmax = 1.07
                text = ""
            intervals [7]:
                xmin = 1.07
                xmax = 1.22
                text = "T"
            intervals [8]:
                xmin = 1.22
                xmax = 1.31
                text = "UW1"
            intervals [9]:
                xmin = 1.31
                xmax = 1.51
                text = "S"
            intervals [10]:
                xmin = 1.51
                xmax = 1.67
                text = "T"
            intervals [11]:
                xmin = 1.67
                xmax = 1.85
                text = "AA1"
            intervals [12]:
                xmin = 1.85
                xmax = 1.88
                text = "P"
            intervals [13]:
                xmin = 1.88
                xmax = 2.53
                text = "sil"
    item [2]:
        class = "IntervalTier"
        name = "words"
        xmin = 0.0
        xmax = 2.53
        intervals: size = 6
            intervals [1]:
                xmin = 0.0
                xmax = 0.62
                text = "sil"
            intervals [2]:
                xmin = 0.62
                xmax = 1.02
                text = "CLICK"
            intervals [3]:
                xmin = 1.02
                xmax = 1.07
                text = "sp"
            intervals [4]:
                xmin = 1.07
                xmax = 1.31
                text = "TO"
            intervals [5]:
                xmin = 1.31
                xmax = 1.88
                text = "STOP"
            intervals [6]:
                xmin = 1.88
                xmax = 2.53
                text = "sil"

The syntax of TextGrid files is a little bit odd. TextGrid文件的语法有点奇怪。 For your restricted purpose, a list of the words and their starting points, your parser could be quite simple: 为了限制您的使用,列出单词及其起点,您的解析器可能非常简单:

  1. Find the text line containing 8 spaces and the string 'name = "words"' 查找包含8个空格和字符串'name =“ words”'的文本行

  2. Inspect all following lines and stop at the next occurence of 8 spaces and the string 'name = "' 检查以下所有行,并在下次出现8个空格和字符串'name =“'时停止

    2a. 2A。 Save the floating point numbers immediately following 12 spaces and the string 'xmin = ' 立即将浮点数保存在12个空格和字符串'xmin ='之后

    2b. 2B。 Save the strings immediately following 12 spaces and the string 'text = ' 立即将字符串保存在12个空格之后,并保存字符串'text ='

The result of this procedure would be: 此过程的结果将是:

0.0 0.62 1.02 1.07 1.31 1.88 0.0 0.62 1.02 1.07 1.31 1.88

"sil" "CLICK" "sp" "TO" "STOP" "sil" “ sil”“点击”“ sp”“到”“停止”“ sil”

Now just re-order these two arrays and you will have your table (the numbers are the starting points given in seconds). 现在,只需对这两个数组重新排序,就可以得到表格(数字是以秒为单位给出的起点)。

Keep in mind that "sil" is an abbreviation for the meta tag "silence" and "sp" for "speech pause". 请记住,“ sil”是元标记“ silence”的缩写,而“ sp”是“ speech pause”的缩写。 While the silence at the beginning and end of an utterance is expected, the speech pause might be wrong because the plosive /t/ of the word "TO" starts with an articulatory occlusion, which is pretty similar to a speech pause, but part of the plosive. 尽管预计语音开始和结束时会保持沉默,但语音暂停可能是错误的,因为单词“ TO”的音高/ t /始于发音闭塞,这与语音暂停非常相似,但其中一部分爆破声。

Since this is a Praat file, and you say you can open it in Praat , I thought a better solution would be to use Praat to solve it. 由于这是一个Praat文件,并且您说可以在Praat打开它,所以我认为一个更好的解决方案是使用Praat来解决它。 A script like the following involves a lot fewer leaps of faith: 如下所示的脚本涉及更少的信念飞跃:

form Parse TextGrid...
  sentence File /path/to/your.TextGrid
  integer Tier 2
endform
Read from file: file$
intervals = Get number of intervals: tier
writeInfoLine: "Word in text", tab$, "Pronounciation started at"
for i to intervals
  label$ = Get label of interval: tier, i
  if label$ != ""
    start = Get start point: tier, i
    appendInfoLine: label$, tab$, string$(start)
  endif
endfor

If you save that into a script somewhere, you could then call Praat from the command line like praat /path/to/your/script.praat "/path/to/your.TextGrid" 2 and get the desired output from stdout . 如果您保存到一个脚本的地方,你可以再调用Praat从像在命令行中praat /path/to/your/script.praat "/path/to/your.TextGrid" 2并从中获取所需的输出stdout

You could also run it manually, and maybe use this to write your file. 您也可以手动运行它,也可以使用来编写文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM