2017-06-03 2 views
0

Ich passe ein Skript an, wo ich für jedes Soundfile und jeden Textgrind in einem Ordner jedes Silbenlabel durchlaufe, das Label in drei gleiche Teile teile und dann extrahiere die Tonhöhe in der Mitte jedes Teils und speichern Sie die Informationen über die Mittelpunkte und die entsprechenden Tonhöhen zu einer Textdatei, die ich im selben Verzeichnis speichern. Wenn ich das Skript ausführe, enthält die generierte Textdatei nur den Header. Wären Sie in der Lage, den Fehler zu identifizieren, der mich daran hindert, auf die Informationen zuzugreifen und/oder sie zu speichern, die ich extrahieren möchte? Unten habe ich das Bit des Codes eingefügt, in dem ich die Mittelpunkte berechne und die Tonhöhe an diesen Punkten extrahiere.Pract Tonhöhenextraktion an berechneten Punkten oder Grenzen (nicht durchschnittliche Tonhöhe in Intervallen)

# Write a row with column titles to the result file: 

titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'" 
fileappend "'resultfile$'" 'titleline$' 

# Go through all the sound files, one by one: 
for i from 1 to numberOfFiles 
    filename$ = Get string... ifile 
    # A sound file is opened from the listing: 
    Read from file: 'sound_directory$''filename$' 

    # Starting from here, you can add everything that should be 
    # repeated for every sound file that was opened: 
    soundname$ = selected$ ("Sound", 1) 
    To Pitch... Time_step Minimum_pitch Maximum_pitch 

    # Open a TextGrid by the same name: 
    gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'" 
    if fileReadable (gridfile$) 
    Read from file... 'gridfile$' 
    # Find the tier number that has the label given in the form: 
    call GetTier 'tier$' tier 
    numberOfIntervals = Get number of intervals... tier 
    # Pass through all intervals in the selected tier: 
    for interval to numberOfIntervals 
     label$ = Get label of interval... tier interval 
     if label$ <> "" 
     # if the interval has an unempty label, get its start and end: 
     start = Get starting point... tier interval 
     end = Get end point... tier interval 
     dur = end - start 

     # divide interval into 3 segments 
     segdur = dur/3 
     midpoint1 = start + (segdur/2) 
     midpoint2 = start + segdur + (segdur/2) 
     midpoint3 = start + (segdur*2) + (segdur/2) 

     # get pitch at each midpoint 
     Move cursor to: midpoint1 
     pitch1 = Get pitch... midpoint1 
     Move cursor to: midpoint2 
     pitch1 = Get pitch... midpoint2 
     Move cursor to: midpoint3 
     pitch1 = Get pitch... midpoint3 

     # Save result to text file: 
     resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'" 
     fileappend "'resultfile$'" 'resultline$' 
     select TextGrid 'soundname$' 
     endif 
    endfor 
    # Remove the TextGrid object from the object list 
    select TextGrid 'soundname$' 
    Remove 
    endif 
    # Remove the temporary objects from the object list 
    select Sound 'soundname$' 
    plus Pitch 'soundname$' 
    Remove 
    select Strings list 
endfor 

Remove 
+0

Das sollte funktionieren. Kannst du ein MWE veröffentlichen? – Stefano

+2

Ihr Codebeispiel ist unvollständig: Es fehlen die Definition des GetTier-Verfahrens und das Anfangsformular – jja

Antwort

0

Vielen Dank für Ihren Hinweis! Nach einigen Stunden des Kampfes mit dem Code konnte ich das Skript zum Laufen bringen. Da es schon ein paar Tage her ist und niemand eine vollständige Antwort veröffentlicht hat, dachte ich mir, dass ich meine veröffentlichen würde, für alles, was es wert ist.

Das Problem war, dass ich Tonhöhe nicht als ein Objekt auswählte, während ich Tonhöhe extrahieren wollte. Wählen Sie zuerst die Tonhöhe select Pitch 'soundname$' und dann den Tonhöhenwert zur angegebenen Zeit pitch1 = Get value at time... time_point Hertz linear. Hoffe das hilft anderen Menschen.

Zur vollständigen Offenlegung wurde dieses Skript von der Github-Website von Mietta Lennes mit Praat-Skriptvorlagen (https://github.com/lennes) angepasst.

# Write a row with column titles to the result file: 
titleline$ = "Filename Syllable Midpoint1 Midpoint2 Midpoint3 Pitch1 Pitch2 Pitch3'newline$'" 
fileappend "'resultfile$'" 'titleline$' 
fileappend "'resultfile$'" "'numberOfFiles'" 

# Go through all the sound files, one by one: 
for ifile to numberOfFiles 
    filename$ = Get string... ifile 
    fileappend "'resultfile$'" 'sound_directory$''filename$' 
    # A sound file is opened from the listing: 
    Read from file... 'sound_directory$''filename$' 

    # Starting from here, you can add everything that should be 
    # repeated for every sound file that was opened: 
    soundname$ = selected$ ("Sound", 1) 
    To Pitch... time_step minimum_pitch maximum_pitch 

    # Open a TextGrid by the same name: 
    gridfile$ = "'textGrid_directory$''soundname$''textGrid_file_extension$'" 

    if fileReadable (gridfile$) 
     Read from file... 'gridfile$' 
     # Find the tier number that has the label given in the form: 
     call GetTier 'tier$' tier 
     numberOfIntervals = Get number of intervals... tier 
     # Pass through all intervals in the selected tier: 
     for interval to numberOfIntervals 
      label$ = Get label of interval... tier interval 
      if label$ <> "" 
       # if the interval has an unempty label, get its start and end: 
       start = Get starting point... tier interval 
       end = Get end point... tier interval 
       dur = end - start 

       # divide interval into 3 segments 
       segdur = dur/3 
       midpoint1 = start + (segdur/2) 
       midpoint2 = start + segdur + (segdur/2) 
       midpoint3 = start + (segdur*2) + (segdur/2) 


       # get pitch at each midpoint 
       select Pitch 'soundname$' 
       pitch1 = Get value at time... midpoint1 Hertz linear 
       pitch2 = Get value at time... midpoint2 Hertz linear 
       pitch3 = Get value at time... midpoint3 Hertz linear 

       # Save result to text file: 
       resultline$ = "'soundname$' 'label$' 'midpoint1' 'midpoint2' 'midpoint3' 'pitch1' 'pitch2' 'pitch3''newline$'" 
       fileappend "'resultfile$'" 'resultline$' 
       select TextGrid 'soundname$' 
      endif 
     endfor 
     # Remove the TextGrid object from the object list 
     select TextGrid 'soundname$' 
     Remove 
    endif 
    # Remove the temporary objects from the object list 
    select Sound 'soundname$' 
    plus Pitch 'soundname$' 
    Remove 
    select Strings list 
endfor 
Verwandte Themen