# **************************************************************************** # * PRAATPIC v. 0.2 (aka super-beta) * # * Draw pretty waveform + spectrogram + textgrid figures * # * Aaron Braver; www.aaronbraver.com/resources/scripts * # **************************************************************************** # INSTRUCTIONS: # # 1. Load up a sound and a textgrid. # 2. Select both the sound and textgrid in the Object window # 3. Press 'View & Edit' to open the Editor window # 4. In the editor window, zoom in so that the portion you want # drawn fills the whole window. (Tip: select the portion you # want to show, then Time > Zoom to selection) # 4b. Do not unselect the sound and textgrid in the Object window # 5. Run this script # 6. To save the image, make sure the pink selection rectangle # contains everything you want to capture. It's ok if something is # in the pink border part. File > Save as PDF file (or whatever). # **************************************************************************** # * FOR AB's TESTING * # **************************************************************************** # sound1 = Read from file: "/Users/abraver/Desktop/prettypicsound.wav" # textgrid1 = Read from file: "/Users/abraver/Desktop/prettypicsound.TextGrid" # select sound1 # plus textgrid1 # View & Edit # **************************************************************************** # * END AB'S TESTING * # **************************************************************************** # Set some default font sizes. # If you edit the script to change these, spacing and margins may # need to be adjusted tick_mark_size = 12 axis_label_size = 16 # **************************************************************************** # * Make sure that an editor window is open * # * and a sound and TextGrid are selected * # **************************************************************************** while numberOfSelected ("TextGrid") = 0 or numberOfSelected("Sound") = 0 beginPause:"Silly goose!" comment: "You didn't have a TextGrid and Sound selected in the Object window!" endPause: "Ok, they're selected now", 1 endwhile extant_editor$ = "" while extant_editor$ = "" edit_window_name$ = "TextGrid " + selected$ ("TextGrid") nocheck editor: edit_window_name$ extant_editor$ = nocheck Editor info endeditor if extant_editor$ = "" beginPause: "Silly goose!" comment: "You didn't have an editor window open ... with your sound and textgrid visible!" comment: "Don't forget to zoom in so the area you want ... drawn fills the entire window." endPause: "Ok, it's open now", 1 endif endwhile # **************************************************************************** # * Get user input * # **************************************************************************** beginPause: "Draw a pretty picture" boolean: "Erase picture window first", 1 real: "Image width (inches)", "7.5" real: "Spectrogram height", "3" boolean: "Start times from zero", 1 real: "Top margin (inches)", "0.5" real: "Left margin (inches)", 1 boolean: "Include waveform", 1 real: "Waveform height", "1.5" comment: "For the spectrogram's y axis:" sentence: "Y axis label (blank for none)", "Frequency (Hz)" optionmenu: "Display frequency tick marks(?)", 1 option: "Every x Hz" option: "Total of x tick marks" option: "No ticks" integer: "Every x Hz", 1000 integer: "Total of x frequency tick marks", "3 (=start, midpoint, and end)" comment: "For the time axis:" sentence: "Time axis label (blank for none)", "Time (s)" optionmenu: "Display time tick marks(?)", 1 option: "Total of x tick marks" option: "Every x seconds" option: "No ticks" integer: "Total of x time tick marks", "2 (=Start and end)" positive: "Every x seconds", 0.1 # comment: "Be sure to have open an editor window with a sound and a TextGrid," # comment: " zoomed in to the area you want drawn." # comment: "The Sound and TextGrid should remain selected in the Object window" comment: "" comment: "Additonal options:" boolean: "Edit fonts", 0 boolean: "Include pitch track over spectrogram", 0 boolean: "Edit pitch track details", 0 endPause: "Continue", 1 # **************************************************************************** # * To edit fonts: * # **************************************************************************** if edit_fonts beginPause: "Edit fonts" optionmenu: "TextGrid label font:", 1 option: "Times" option: "Helvetica" option: "Palatino" option: "Courier" integer: "TextGrid label size", "24 (=14 is Praat's default)" optionmenu: "Axis label font:", 1 option: "Times" option: "Helvetica" option: "Palatino" option: "Courier" optionmenu: "Tick mark font:", 1 option: "Times" option: "Helvetica" option: "Palatino" option: "Courier" # comment: "Be sure to have open an editor window with a sound and a TextGrid," # comment: " zoomed in to the area you want drawn." # comment: "The Sound and TextGrid should remain selected in the Object window" endPause: "Continue", 1 else textGrid_label_font$ = "Times" textGrid_label_size = 24 axis_label_font$ = "Times" tick_mark_font$ = "Times" endif # **************************************************************************** # * To edit pitch-track details * # **************************************************************************** if edit_pitch_track_details if !include_pitch_track_over_spectrogram beginPause: "Silly goose!" comment: "On the first screen you said you didn't want a pitch track," comment: "But you also said you wanted to edit pitch track details." comment: "" really_no_pitch_track = endPause: "Leave out pitch track", "Include pitch track", 2 if really_no_pitch_track = 2 include_pitch_track_over_spectrogram = 1 endif endif if include_pitch_track_over_spectrogram beginPause: "Pitch track details" sentence: "Pitch track color:", "Blue" comment: "*For possible color values, see:" comment: " https://www.fon.hum.uva.nl/praat/manual/Colour.html" comment: "" optionmenu: "Pitch track line type:", 1 option: "Solid line" option: "Dotted line" option: "Dashed line" option: "Dashed-dotted line" positive: "Pitch track line width:", 2 comment: "For the righthand y axis of the spectrogram/pitch track:" sentence: "Pitch axis label (blank for none)", "Pitch (Hz)" optionmenu: "Display pitch tick marks(?)", 1 option: "Every x Hz" option: "Total of x tick marks" option: "No ticks" integer: "Every x Hz for pitch", 200 integer: "Total of x pitch tick marks", "3 (=start, midpoint, and end)" comment: "To change range, etc, use Pitch > Pitch Settings in the editor window." endPause: "Continue", 1 endif else pitch_track_color$ = "Blue" pitch_track_line_type$ = "Solid line" pitch_track_line_width = 2 pitch_axis_label$ = "Pitch (Hz)" display_pitch_tick_marks$ = "Total of x pitch tick marks" every_x_Hz_for_pitch = 200 total_of_x_pitch_tick_marks = 3 endif if erase_picture_window_first Erase all endif # Compute some values waveform_top = top_margin if include_waveform waveform_bottom = waveform_top + waveform_height else waveform_bottom = waveform_top waveform_height = 0 endif spectrogram_top = waveform_bottom spectrogram_bottom = spectrogram_top + spectrogram_height # Get some info from the editor editor: edit_window_name$ selection_duration = Get length of visible part textgrid_info$ = TextGrid info x_editor_info$ = Editor info ntiers = extractNumber(textgrid_info$, "interval tiers:") + extractNumber(textgrid_info$, "point tiers:") pitch_shown = extractNumber(x_editor_info$, "Pitch show:") pitch_floor = extractNumber(x_editor_info$, "Pitch floor:") pitch_ceiling = extractNumber(x_editor_info$, "Pitch ceiling:") endeditor # Get and set some initial values from the picture window Line width: 0.5 picture_info$ = Picture info starting_color$ = extractLine$ (picture_info$, "Colour:") starting_line_width = extractNumber (picture_info$, "Line width:") starting_line_type$ = extractLine$ (picture_info$, "Line type: ") + " line" main_line_and_text_color$ = "Black" Colour: main_line_and_text_color$ # **************************************************************************** # * Draw waveform * # **************************************************************************** if include_waveform Select inner viewport: left_margin, image_width, top_margin, waveform_bottom Draw inner box editor: edit_window_name$ Draw visible sound: "no", "no", 0, 0, ..."no", "no", "no", "no" endeditor endif Line width: 0.5 # **************************************************************************** # * Draw spectrogram * # **************************************************************************** Select inner viewport: left_margin, image_width, spectrogram_top, spectrogram_bottom editor: edit_window_name$ Paint visible spectrogram: "no", "no", "no", "no", "no" endeditor Draw inner box # Draw the correct kind of tick marks Font size: tick_mark_size; NB: changing font size will mess with the margins! do: tick_mark_font$ Select inner viewport: left_margin, image_width, spectrogram_top, spectrogram_bottom if display_frequency_tick_marks$ != "No ticks" if display_frequency_tick_marks$ = "Every x Hz" Colour: main_line_and_text_color$ Marks left every: 1.0, every_x_Hz, "yes", "yes", "no" elif display_frequency_tick_marks$ = "Total of x tick marks" Colour: main_line_and_text_color$ Marks left: total_of_x_frequency_tick_marks, "yes", "no", "no" endif # Draw axis label Font size: axis_label_size Select inner viewport: left_margin, image_width, spectrogram_top, spectrogram_bottom do: axis_label_font$ Colour: main_line_and_text_color$ if y_axis_label$ != "" do: axis_label_font$ Text left: "yes", y_axis_label$ endif endif # Draw the pitch track if needed if include_pitch_track_over_spectrogram Colour: pitch_track_color$ do: pitch_track_line_type$ Line width: pitch_track_line_width editor: edit_window_name$ if pitch_shown != 1 Show pitch endif Draw visible pitch contour: "no", "no", "no", "no", "no", "no" endeditor # Pitch track y axis on the right # Reset color and such first Colour: main_line_and_text_color$ do: starting_line_type$ Line width: starting_line_width if display_pitch_tick_marks$ != "No ticks" Font size: axis_label_size; NB: changing font size will mess with the margins! Select inner viewport: left_margin, image_width, spectrogram_top, spectrogram_bottom Axes: 0, 1, pitch_floor, pitch_ceiling Text right: "yes", pitch_axis_label$; Axis label Font size: tick_mark_size; NB: changing font size will mess with the margins! do: tick_mark_font$ Select inner viewport: left_margin, image_width, spectrogram_top, spectrogram_bottom if display_pitch_tick_marks$ = "Every x Hz" Marks right every: 1.0, every_x_Hz_for_pitch, "yes", "yes", "no" elif display_time_tick_marks$ = "Total of x tick marks" Marks right: total_of_x_pitch_tick_marks, "yes", "no", "no"; Pitch tick marks endif endif endif # **************************************************************************** # * Draw textrgrid * # **************************************************************************** Line width: 1 Font size: textGrid_label_size; NB: changing font size will mess with the margins! do: textGrid_label_font$ Select inner viewport: left_margin, image_width, top_margin, ... (spectrogram_bottom + ((waveform_height + spectrogram_height)/4)*ntiers) editor: edit_window_name$ Draw visible TextGrid: "no", "no", "no", "no", "no" endeditor # **************************************************************************** # * Axes * # **************************************************************************** Font size: axis_label_size; NB: changing font size will mess with the margins! picture_info$ = Picture info axis_top = extractNumber(picture_info$, "Axis top:") axis_bottom = extractNumber(picture_info$, "Axis bottom:") axis_left = extractNumber(picture_info$, "Axis left:") axis_right = extractNumber(picture_info$, "Axis right:") if start_times_from_zero max_time = axis_right - axis_left Axes: 0, max_time, axis_bottom, axis_top endif Font size: axis_label_size; NB: changing font size will mess with the margins! Select inner viewport: left_margin, image_width, top_margin, ... (spectrogram_bottom + ((waveform_height + spectrogram_height)/4)*ntiers) Text bottom: "yes", time_axis_label$; Axis label Font size: tick_mark_size; NB: changing font size will mess with the margins! do: tick_mark_font$ Select inner viewport: left_margin, image_width, top_margin, ... (spectrogram_bottom + ((waveform_height + spectrogram_height)/4)*ntiers) if display_time_tick_marks$ = "Every x seconds" Marks bottom every: 1.0, every_x_seconds, "yes", "yes", "no" elif display_time_tick_marks$ = "Total of x tick marks" Marks bottom: total_of_x_time_tick_marks, "yes", "no", "no"; Time tick marks endif # Return the selection to reasonable Font size: 16 Select inner viewport: left_margin, image_width, top_margin, ... (spectrogram_bottom + ((waveform_height + spectrogram_height)/4)*ntiers)