Update README.md
Browse files
README.md
CHANGED
|
@@ -230,7 +230,7 @@ for it in recognition_result['chunks']:
|
|
| 230 |
|
| 231 |
recognition_result = asr(
|
| 232 |
sound_en,
|
| 233 |
-
generate_kwargs={'task': 'transcribe', 'language': 'english',
|
| 234 |
return_timestamps=True
|
| 235 |
)
|
| 236 |
print('\nRecognized chunks of English speech:')
|
|
@@ -256,6 +256,85 @@ Recognized chunks of English speech:
|
|
| 256 |
{'timestamp': (8.96, 20.08), 'text': 'We can decrease variance on basis of large ensemble, large ensemble of different algorithms.'}
|
| 257 |
```
|
| 258 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
#### Voice activity detection (speech/non-speech)
|
| 260 |
|
| 261 |
Along with special language tokens, the model can also return the special token `<|nospeech|>`, if the input audio signal does not contain any speech (for details, see section 2.3 of the [corresponding paper about Whisper](https://arxiv.org/pdf/2212.04356)). This skill of the model forms the basis of the speech/non-speech classification algorithm, as demonstrated in the following example:
|
|
|
|
| 230 |
|
| 231 |
recognition_result = asr(
|
| 232 |
sound_en,
|
| 233 |
+
generate_kwargs={'task': 'transcribe', 'language': 'english'},
|
| 234 |
return_timestamps=True
|
| 235 |
)
|
| 236 |
print('\nRecognized chunks of English speech:')
|
|
|
|
| 256 |
{'timestamp': (8.96, 20.08), 'text': 'We can decrease variance on basis of large ensemble, large ensemble of different algorithms.'}
|
| 257 |
```
|
| 258 |
|
| 259 |
+
#### Long-form speech recognition
|
| 260 |
+
|
| 261 |
+
While previous examples demonstrate accurate transcription for audio segments under thirty seconds, practical applications often require processing extensive recordings ranging from several minutes to multiple hours. This necessitates specialized techniques like the sliding window approach to overcome memory constraints and preserve contextual coherence across the entire signal. The following example showcases the model's capability to handle such long-form audio, enabling accurate transcription of lectures, interviews, and meetings.
|
| 262 |
+
|
| 263 |
+
```python
|
| 264 |
+
import nltk # for splitting long text into sentences
|
| 265 |
+
from whisper_lid.whisper_lid import detect_language_in_long_speech # for spoken language detection in long audio
|
| 266 |
+
|
| 267 |
+
nltk.download('punkt_tab')
|
| 268 |
+
|
| 269 |
+
long_sound_ru_url = 'https://huggingface.co/bond005/whisper-podlodka-turbo/resolve/main/test_sound_ru_longform.wav'
|
| 270 |
+
long_sound_ru_name = wget.download(long_sound_ru_url)
|
| 271 |
+
long_sound_ru = librosa.load(long_sound_ru_name, sr=target_sampling_rate, mono=True)[0]
|
| 272 |
+
print('Duration of long sound with Russian speech = {0:.3f} seconds.'.format(
|
| 273 |
+
sound_ru.shape[0] / target_sampling_rate
|
| 274 |
+
))
|
| 275 |
+
|
| 276 |
+
detected_languages, _ = detect_language_in_long_speech(
|
| 277 |
+
long_sound_ru,
|
| 278 |
+
asr.feature_extractor,
|
| 279 |
+
asr.tokenizer,
|
| 280 |
+
asr.model
|
| 281 |
+
)
|
| 282 |
+
print('\nTop-3 languages:')
|
| 283 |
+
lang_text_width = max([len(it[0]) for it in detected_languages])
|
| 284 |
+
for it in detected_languages[0:3]:
|
| 285 |
+
print(' {0:>{1}} {2:.4f}'.format(it[0], lang_text_width, it[1]))
|
| 286 |
+
|
| 287 |
+
recognition_result = asr(
|
| 288 |
+
sound_ru_longform,
|
| 289 |
+
generate_kwargs={
|
| 290 |
+
'max_new_tokens': 410,
|
| 291 |
+
'num_beams': 5, # beam search width (higher values improve accuracy at the cost of increased computation)
|
| 292 |
+
'condition_on_prev_tokens': False,
|
| 293 |
+
'compression_ratio_threshold': 2.4, # used to detect and suppress repetitive loops (a common failure mode)
|
| 294 |
+
'temperature': (0.0, 0.2, 0.4, 0.6, 0.8, 1.0), # controls the randomness of token sampling during generation
|
| 295 |
+
'logprob_threshold': -1.0, # the threshold for the average log-probability of the generated tokens (provides a filter to exclude low-confidence, potentially erroneous transcriptions)
|
| 296 |
+
'no_speech_threshold': 0.6, # threshold for the probability of the `<|nospeech|>` token (segments with a probability above this threshold are considered silent and skipped)
|
| 297 |
+
'task': 'transcribe',
|
| 298 |
+
'language': detected_languages[0][0]
|
| 299 |
+
},
|
| 300 |
+
return_timestamps=True
|
| 301 |
+
)
|
| 302 |
+
print('\nRecognized text in the long audio, split into sentences:')
|
| 303 |
+
for it in map(lambda sent: sent.strip(), nltk.sent_tokenize(recognition_result['text'])):
|
| 304 |
+
print(f' {it}')
|
| 305 |
+
```
|
| 306 |
+
|
| 307 |
+
As a result, you can see a text output like this:
|
| 308 |
+
|
| 309 |
+
```text
|
| 310 |
+
Duration of long sound with Russian speech = 148.845 seconds.
|
| 311 |
+
|
| 312 |
+
Top-3 languages:
|
| 313 |
+
russian 0.9787
|
| 314 |
+
english 0.0186
|
| 315 |
+
ukrainian 0.0006
|
| 316 |
+
|
| 317 |
+
Recognized text in the long audio, split into sentences:
|
| 318 |
+
Здравствуйте, друзья!
|
| 319 |
+
Здравствуйте!
|
| 320 |
+
Я очень рад вас всех видеть здесь, в этом зале на Хайлооде.
|
| 321 |
+
Я Иван, как меня уже представили, и я люблю машинное обучение.
|
| 322 |
+
Я люблю машинное обучение с 2005 года, когда оно проникло в моё сердце ещё, когда я был студентом.
|
| 323 |
+
С 2006 года я работал в академической сфере, преподавал нейронные сети, искусственный интеллект, машинное обучение своим студентам.
|
| 324 |
+
С тринадцатого года я перешёл в IT-индустрию, работал в разных компаниях, занимаясь примерно всё тем же машинным обучением и искусством интеллектом.
|
| 325 |
+
И, наконец, в двадцать втором году мне всё это надоело, я решил обратно из IT-индустрии перейти в академическую сферу.
|
| 326 |
+
И сейчас я работаю в Новосибирском государственном университете, занимаюсь научными исследованиями, учу студентов, делаем всякие интересные штуки.
|
| 327 |
+
Ну, а в конце прошлого года я и мои ученики решили всё-таки не только фундаментальными исследованиями заниматься, и наука должна проносить пользу людям, и мы сделали маленький стартап под названием «Сибирские нейросети».
|
| 328 |
+
То есть, сибирское здоровье и сибирские нейросети теперь.
|
| 329 |
+
Всё, что я делал, оно связано одним, моей любовью к машинному обучению.
|
| 330 |
+
Мне это очень интересно было всегда.
|
| 331 |
+
Ну, а помимо машинного обучения, мне интересно участвовать в соревнованиях.
|
| 332 |
+
Научные соревнования — это не просто способ развлечься, это способ оценить по гамбургскому счету, насколько твой алгоритм хорош объективно в сравнении с другими.
|
| 333 |
+
Когда мы разрабатываем какую-то систему для заказчика, мы ориентируемся на его данные, эти данные закрыты, как правило, мы делаем какие-то кастомизации, которые обеспечивают качество, может, даже черепикинг иногда делаем, хотя это фу, но тем не менее.
|
| 334 |
+
А когда мы предлагаем наши решения, наш научный метод, наш алгоритм на соревновании, мы все в равных условиях, и мы действительно можем оценить, насколько хорошо то или иное решение себя показывает.
|
| 335 |
+
При этом самое главное, что такие соревнования дают материалы в виде открытых датасетов для дальнейшей воспроизводимости, в виде открытого кода, который, опять-таки, можно воспроизводить в науке, проблема воспроизводимости стоит остро, А подобные научные соревнования, я имею в виду не Кегл, а что-то более интересное и более такое системное, они позволяют действительно какое-то движение науки вперед осуществлять.
|
| 336 |
+
```
|
| 337 |
+
|
| 338 |
#### Voice activity detection (speech/non-speech)
|
| 339 |
|
| 340 |
Along with special language tokens, the model can also return the special token `<|nospeech|>`, if the input audio signal does not contain any speech (for details, see section 2.3 of the [corresponding paper about Whisper](https://arxiv.org/pdf/2212.04356)). This skill of the model forms the basis of the speech/non-speech classification algorithm, as demonstrated in the following example:
|