Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding issue when outputting results_to_word_srt #8

Closed
Duglz opened this issue Oct 11, 2022 · 1 comment
Closed

Encoding issue when outputting results_to_word_srt #8

Duglz opened this issue Oct 11, 2022 · 1 comment

Comments

@Duglz
Copy link

Duglz commented Oct 11, 2022

I'm new to python but wanted to share this incase anyone else has this issue.
Python Script

import whisper
from stable_ts.stable_whisper import modify_model
from stable_ts.stable_whisper import results_to_word_srt


model = whisper.load_model("medium")
modify_model(model)
results = model.transcribe("test.mp3")
stab_segments = results['segments']
first_segment_word_timestamps = stab_segments[0]['whole_word_timestamps']

results_to_word_srt(results, 'audio.srt', combine_compound=True)

Error:

Traceback (most recent call last):
  File "C:\scripts\whispertest.py", line 12, in <module>
    srt = results_to_word_srt(results, 'audio.srt')
  File "C:\scripts\stable_ts\stable_whisper.py", line 223, in results_to_word_srt
    to_srt(group_word_timestamps(res, combine_compound=combine_compound), srt_path)
  File "C:\scripts\stable_ts\stable_whisper.py", line 109, in to_srt
    f.write(srt_str)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1776.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u30b5' in position 10570: character maps to <undefined>

Fix stable_whisper.py lines 107-110:

    if save_path:
        with open(save_path, 'w', encoding="utf-8") as f:
            f.write(srt_str)
        print(f'Saved: {os.path.abspath(save_path)}')
@jianfch
Copy link
Owner

jianfch commented Oct 11, 2022

thanks! should fixed in f913547

@jianfch jianfch closed this as completed Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants