Giter Site home page Giter Site logo

circletreef / stable-ts-con Goto Github PK

View Code? Open in Web Editor NEW

This project forked from anoncheg1/stable-ts-con

0.0 0.0 0.0 235 KB

Stable timestamps and confidence score for words of OpenAI's Whisper outputs down to word-level.

License: MIT License

Python 100.00%

stable-ts-con's Introduction

Stabilizing Timestamps and confidence scores for Whisper

Description

This script modifies methods of Whisper's model to gain access to the predicted timestamp tokens of each word (token) without needing additional inference. It also stabilizes the timestamps down to the word (token) level to ensure chronology. Additionally, it can suppress gaps in speech for more accurate timestamps.

image

Confidence score is a log_softmax used for sum_logprobs also.

F.log_softmax(logits.float(), dim=-1)

Screenshot_2022-12-15_12-25-55

TODO

  • Add function to stabilize with multiple inferences

Dependency

Setup

Option 1: Install Whisper+stable-ts-con (one line)

pip install git+https://github.com/Anoncheg1/stable-ts-con.git

Option 2 (without confidence): Install Whisper (repo) and stable-ts (PyPI) separately

  1. Install Whisper
  2. Check if Whisper is installed correctly by running a quick test
import whisper
model = whisper.load_model('base')
assert model.transcribe('audio.mp3').get('segments')
  1. Install stable-ts
pip install stable-ts

Executing script

from stable_whisper import load_model

model = load_model('base')
# modified model should run just like the regular model but with additional hyperparameters and extra data in results
results = model.transcribe('audio.mp3')
stab_segments = results['segments']
first_segment_word_timestamps = stab_segments[0]['whole_word_timestamps']

# or to get token timestamps that adhere more to the top prediction
from stable_whisper import stabilize_timestamps
stab_segments = stabilize_timestamps(results, top_focus=True)

Generate .srt with stable timestamps

# word-level
from stable_whisper import results_to_word_srt
# after you get results from modified model
# this treats a word timestamp as end time of the word
# and combines words if their timestamps overlap
results_to_word_srt(results, 'audio.srt')  # combine_compound=True will merge words with no prepended space
# sentence/phrase-level
from stable_whisper import results_to_sentence_srt
# after you get results from modified model
results_to_sentence_srt(results, 'audio.srt')
# below is from large model default settings
jfk_phrases.mp4
# sentence/phrase-level & word-level
from stable_whisper import results_to_sentence_word_ass
# after you get results from modified model
results_to_sentence_word_ass(results, 'audio.ass')
# below is from large model default settings
jfk_phrases_words.mp4

Additional Info

  • Since the sentence/segment-level timestamps are predicted directly, they are always more accurate and precise than word/token-level timestamps.
  • Although timestamps are chronological, they can still be off sync depending on the model and audio.
  • The unstable_word_timestamps are left in the results, so you can possibly find better way to utilize them.

License

This project is licensed under the MIT License - see the LICENSE file for details

Acknowledgments

Includes slight modification of the original work: Whisper

stable-ts-con's People

Contributors

jianfch avatar vitalij23 avatar navalnica avatar eschmidbauer avatar anoncheg1 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.