Skip to contents

Introduction

This vignette demonstrates how to use the set of functions to process raw interview transcripts and reconstruct a dialogue sequence suitable for analysis or reporting. This set of functions handle speaker identification, data structuring, intervention extraction, and output formatting. We will illustrate two equivalent approaches: step-by-step processing and using a wrapper function for streamlined operation.

Data

This set of functions expect transcript formatted with each line tagged with the speaker’s name enclosed in square brackets:

[Speaker1] This is the first question.
[Speaker2] And here is my answer to that question.
[Speaker1] Okay, good. Let's move on...

An example of interview transcript is shipped with the package in the form of a text file. To access proceed as follows:

data_path = system.file("extdata", package = "so.ii")

Once the path is set, we use the read_interview() function to load the raw interview transcript:

# load interview file
interview = read_interview(file.path(data.path, "interview.txt"))
interview

The set of functions to process raw interview transcripts provides a flexible and efficient way to process interview transcripts for various analytical or reporting purposes. You can choose a step-by-step approach for greater control or a wrapper function for simplified operation. The resulting file can then be used for further analysis, visualization, or documentation.

Let us walk you through each of the alternatives:

Alternative 1: Step-by-Step Processing

This approach breaks down the processing into individual steps, providing more control and visibility at each stage.

Step 1: Retrieve Speakers

First, we use the retrieve_speaker() function to identify all unique speakers present in the transcript:

speaker = retrieve_speaker(interview)
speaker

This will output a character vector containing the names of all identified speakers (e.g., "SPEAKER_00" "SPEAKER_01" "UNKNOWN").

Step 2: Generate Speaker Pattern

Next, we create a regular expression pattern to match the speaker tags in the transcript using generate_speaker_pattern():

pattern = generate_speaker_pattern(speaker)
pattern

This will output a regular expression string like "\\[SPEAKER_00\\] |\\[SPEAKER_01\\] |\\[UNKNOWN\\] ".

Step 3: Structure Interview Data

We then use prep_interview() to structure the transcript by grouping consecutive lines spoken by the same speaker into segments.

structured_interview = prep_interview(interview)

The structured_interview object is now a named list where each element contains the lines spoken by one speaker in consecutive turns.

Step 4: Process Structured Interview

Now we extract and concatenate interventions using process_structured_interview(). This function removes the speaker tags from within each turn and combines them into a single string per segment.

concatenated_interview = process_structured_interview(
  structured_interview,
  pattern
)

Please note that strings tagged as ‘[UNKNOWN]’ are left unprocessed so that you can check them and assign the appropriate speaker tag.

Step 5: Unlist Interventions

We then use unlist_processed_interview() to combine the interventions into a single character vector and prepend the speaker tags back to each line.

processed_interview = unlist_processed_interview(concatenated_interview)

Alternative 2: Using the Wrapper Function

The process_interview() function encapsulates all the above steps into a single call. This provides a more concise way to process interview transcripts.

processed_interview = process_interview(interview)

This single line of code achieves the same result as the six-step approach described above. The output will be identical.

Rename known speakers

The rename_speaker() function enables you to rename speaker tags. For example, you might want to change the tags SPEAKER_00 and SPEAKER_01 to Mary and Marylou, while leaving UNKNOWN as it is:

processed_interview_renamed = rename_speaker(
  interview = intrw, 
  current_speaker = speaker[!speaker == "UNKNOWN"],
  new_speaker = c("Mary", "Marylou")
)

Store output

Step 6: Store Results

Finally, we save the processed transcript to a file using write_interview():

write_interview(processed_interview, file.path(tempdir(), "test_sequence.md"))

This creates a markdown file named test_sequence.md containing the reconstructed dialogue sequence with speaker tags.