File size: 1,919 Bytes
6abeb51
8a3de9a
6abeb51
8a3de9a
 
 
 
6abeb51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
46
47
48
import sys

file_path = r"C:\Users\o\.conda\envs\NeMo\Lib\site-packages\nemo\collections\asr\data\audio_to_text.py"

with open(file_path, "r", encoding="utf-8") as f:
    content = f.read()

old_str = """            def __next__(self):
                if self.current_fn is None:
                    self.current_bytes, self.current_fn = next(self.iterator)
                    self.offset_id = 0
                else:
                    offset_list = self.collection.mapping[self.current_fn]
                    if len(offset_list) == self.offset_id + 1:
                        self.current_bytes, self.current_fn = next(self.iterator)
                        self.offset_id = 0
                    else:
                        self.offset_id += 1

                return self.current_bytes, self.current_fn, self.offset_id"""

new_str = """            def __next__(self):
                if self.current_fn is None:
                    self.current_bytes, self.current_fn = next(self.iterator)
                    self.offset_id = 0
                else:
                    import os
                    file_id, _ = os.path.splitext(os.path.basename(self.current_fn))
                    offset_list = self.collection.mapping[file_id]
                    if len(offset_list) == self.offset_id + 1:
                        self.current_bytes, self.current_fn = next(self.iterator)
                        self.offset_id = 0
                    else:
                        self.offset_id += 1

                return self.current_bytes, self.current_fn, self.offset_id"""

if old_str in content:
    content = content.replace(old_str, new_str)
    with open(file_path, "w", encoding="utf-8") as f:
        f.write(content)
    print("Successfully patched audio_to_text.py!")
else:
    if new_str in content:
        print("Already patched!")
    else:
        print("Could not find the target string to patch.")