File size: 1,497 Bytes
67d6834
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import os
import json

def annotate_pauses(session_id, threshold, base_dir="session_data"):

    session_dir = os.path.join(base_dir, session_id)
    json_file = os.path.join(session_dir, f"{session_id}_transcriptionCW.json")
    
    if not os.path.exists(json_file):
        print(f"Error: could not finf {json_file}")
        return
    
    with open(json_file, "r", encoding="utf-8") as f:
        data = json.load(f)
    
    segments = data.get("segments", [])
    for segment in segments:
        words = segment.get("words", [])
        if "pauses" in segment:
            del segment["pauses"]
            
        pauses = []
        if words and len(words) > 1:
            for i in range(1, len(words)):
                prev_word = words[i - 1]
                current_word = words[i]
                gap = current_word["start"] - prev_word["end"]
                if gap > threshold:
                    pause_info = {
                        "start": round(prev_word["end"], 3),
                        "end": round(current_word["start"], 3),
                        "duration": round(gap, 3)
                    }
                    pauses.append(pause_info)
        segment["pauses"] = pauses
    
    with open(json_file, "w", encoding="utf-8") as f:
        json.dump(data, f, ensure_ascii=False, indent=4)
    
    print(f"Session {session_id} pause annotation done: {json_file}")
    return data

if __name__ == "__main__":
    annotated_data = annotate_pauses("000030", 0.1)