| 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.") |
|
|