Compare commits

...

47 Commits

Author SHA1 Message Date
Nickolay Shmyrev cf2560c9f8 Bump debian requirement 2022-12-14 17:58:40 +01:00
Nickolay Shmyrev 800d3d7089 Bump version 2022-12-14 17:38:53 +01:00
Nickolay Shmyrev b471207f7a Protect against segmentation faults with corrupted model folder 2022-12-14 17:32:55 +01:00
Edwin Hendriks 25c59b52e3 add -m (language model) argument to test_microphone.py (#1219)
* added language model as parameter

* fix fore more help explanation
2022-12-07 22:53:21 +03:00
Nickolay Shmyrev 4c72097478 Allow to configure GPU model path. See https://github.com/alphacep/vosk-server/issues/207 2022-11-19 01:13:42 +01:00
Tomas Mehdi 1053cfa0f8 JSON output_type with texts (#1180) 2022-10-26 22:41:04 +03:00
gmat 21a42cb6cd new output type json for gecko project (#1166)
add a output type `json` to get output file compatible with transcription file format for the gecko project annotation https://github.com/gong-io/gecko
2022-10-06 16:27:29 +03:00
Nickolay Shmyrev 16c4a0d985 Bump version 2022-09-25 21:00:24 +02:00
Nickolay Shmyrev 298253401a Update approach to machine detection on cross-compilation
See for details issue #1155
2022-09-25 21:00:24 +02:00
Nickolay Shmyrev 32aa980069 Allow to change grammar of existing recognizer. Probably can be faster though
if we do not reinit feature pipeline
2022-09-13 23:12:13 +02:00
vadimdddd 7b4d396eb1 fix quotes and import's order (#1143) 2022-09-13 21:51:45 +03:00
vadimdddd 36968fbb30 Fix python style issues (#1140)
* pylint_fix v.2

* init: fix quotes
2022-09-12 23:08:59 +03:00
vadimdddd 7474888801 Fix python style issues (#1131) 2022-09-09 00:13:02 +03:00
vadimdddd d46b7a43eb Split results by newlines (#1124) 2022-08-26 17:22:10 +03:00
vadimdddd 2376b32a8a Add SRTResult to KaldiRecognizer (#1080) 2022-08-24 12:48:18 +03:00
vadimdddd b8a88cc30c Add gradio recognizer (#1114)
Demonstrate speech recognition in gradio
2022-08-19 17:31:47 +03:00
Nickolay V. Shmyrev be0b117711 Add training colab 2022-08-17 19:11:45 +02:00
Nickolay V. Shmyrev 449c8ea5af Introduce stop stage espnet style 2022-08-17 14:30:56 +02:00
Nickolay V. Shmyrev 900da76652 Import script locally 2022-08-17 12:50:59 +02:00
Nickolay V. Shmyrev df0ee24084 Add adaptation colab 2022-08-17 12:38:17 +02:00
Nickolay V. Shmyrev d3d8f53156 Add Kaldi build colab 2022-08-17 10:02:43 +02:00
vadimdddd 6eee303d7e Fix decoding files with spaces (#1084)
Fix decoding files with spaces
2022-08-02 20:56:04 +03:00
Nickolay Shmyrev 053d71f5aa Bug fix in notebook 2022-08-01 22:59:38 +02:00
Nickolay Shmyrev 4fbbf5882c Add colab demo 2022-08-01 22:52:57 +02:00
Nickolay Shmyrev 7012103b3b Simplify the go interface. Move from []byte to strings. Fixes #1095 2022-07-31 09:58:33 +02:00
Nickolay Shmyrev 967024d20a Fix precedence of current path for dll load. Fixes issue #1096 2022-07-30 09:15:28 +02:00
Nicolas Dato b966a8078b Fix comment (#1091) 2022-07-26 23:07:25 +03:00
vadimdddd f63b015284 Add new dependency websockets (#1079)
add websockets to dependencies
2022-07-19 19:58:24 +03:00
Nickolay Shmyrev 0a9672d910 Attempt to build manylinux wheel 2022-07-15 00:40:38 +02:00
Nickolay Shmyrev 4ccccd0cd2 Bump version 2022-07-14 21:38:36 +02:00
Nickolay Shmyrev 354fb672a3 Merge branch 'master' of github.com:alphacep/vosk-api 2022-07-13 14:09:05 +02:00
Nickolay Shmyrev 73abf0740a Add Ruby bindings 2022-07-13 14:08:50 +02:00
Nickolay Shmyrev 81c82935ac Add usage example 2022-07-07 01:09:32 +02:00
Nickolay Shmyrev ac3ec56584 Add notes about Go and Rust 2022-07-05 01:18:08 +02:00
Nickolay Shmyrev 2cbe12d4d0 Add link to rust bindings 2022-07-05 01:17:43 +02:00
Nickolay Shmyrev 1475b0e986 Async ffmpeg for trancriber and code refactoring 2022-07-05 01:13:05 +02:00
vadimdddd 8ceab0b9b1 Add vosk-server to transcriber (#1024)
Allow to use vosk-server for transcription
2022-07-04 13:50:38 +03:00
Nickolay Shmyrev 1496b597d3 Fixes issues with models without alignment 2022-07-03 13:00:05 +02:00
vadimdddd 983519e629 Add compatibility with python 3.5 issue(#1021) (#1041)
Added format for python3.5
2022-06-29 18:00:40 +03:00
Nickolay Shmyrev 58fa98ccd7 Wait for microphone to finalize. Fixes crash in issue #1034 2022-06-28 01:01:53 +03:00
Nickolay Shmyrev a7bc5a22d4 We support Polish now 2022-06-05 23:03:57 +02:00
Rémi Bernon 23bbff0b56 build: Add a CMakeLists.txt. (#992) 2022-06-04 17:34:42 +03:00
Kay Gosho a47b58e2f4 Specify device to get microphone input (#993) 2022-06-03 15:33:50 +03:00
Nickolay Shmyrev 8cf64ee93e Add RISCV support 2022-06-02 01:44:16 +02:00
vadimdddd 630edeb3d6 fixed error if parent directory doesn't exist #988 (#990)
Create missing parent directory
2022-06-01 17:52:16 +03:00
Nickolay Shmyrev b1b216d4c8 Bump versions 2022-05-26 15:22:16 +02:00
Nickolay Shmyrev 55dd29b0ff Fix transcriber bugs while processing folder 2022-05-26 14:05:54 +02:00
64 changed files with 15525 additions and 488 deletions
+20
View File
@@ -0,0 +1,20 @@
cmake_minimum_required(VERSION 3.13)
project(vosk-api CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
add_library(vosk
src/language_model.cc
src/model.cc
src/recognizer.cc
src/spk_model.cc
src/vosk_api.cc
)
find_package(kaldi REQUIRED)
target_link_libraries(vosk PUBLIC kaldi-base kaldi-online2 kaldi-rnnlm fstngram)
include(GNUInstallDirs)
install(TARGETS vosk DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES src/vosk_api.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+3 -2
View File
@@ -4,14 +4,15 @@ Vosk is an offline open source speech recognition toolkit. It enables
speech recognition for 20+ languages and dialects - English, Indian
English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish,
Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino,
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech. More to come.
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish.
More to come.
Vosk models are small (50 Mb) but provide continuous large vocabulary
transcription, zero-latency response with streaming API, reconfigurable
vocabulary and speaker identification.
Speech recognition bindings implemented for various programming languages
like Python, Java, Node.JS, C#, C++ and others.
like Python, Java, Node.JS, C#, C++, Rust, Go and others.
Vosk supplies speech recognition for chatbots, smart home appliances,
virtual assistants. It can also create subtitles for movies,
+1 -1
View File
@@ -10,7 +10,7 @@ buildscript {
}
allprojects {
version = '0.3.41'
version = '0.3.45'
}
subprojects {
+1 -1
View File
@@ -11,7 +11,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Vosk" Version="0.3.41" />
<PackageReference Include="Vosk" Version="0.3.45" />
</ItemGroup>
</Project>
+1 -1
View File
@@ -2,7 +2,7 @@
<package>
<metadata>
<id>Vosk</id>
<version>0.3.41</version>
<version>0.3.45</version>
<authors>Alpha Cephei Inc</authors>
<owners>Alpha Cephei Inc</owners>
<license type="expression">Apache-2.0</license>
+1
View File
@@ -0,0 +1 @@
See example subfolder for instructions how to use the module
+31
View File
@@ -0,0 +1,31 @@
To try this package do the following steps:
On Linux (we download library and set LD_LIBRARY_PATH)
```
git clone https://github.com/alphacep/vosk-api
cd vosk-api/go/example
wget https://github.com/alphacep/vosk-api/releases/download/v0.3.45/vosk-linux-x86_64-0.3.45.zip
unzip vosk-linux-x86_64-0.3.45.zip
wget https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
unzip vosk-model-small-en-us-0.15.zip
mv vosk-model-small-en-us-0.15 model
cp ../../python/example/test.wav .
VOSK_PATH=`pwd`/vosk-linux-x86_64-0.3.45 LD_LIBRARY_PATH=$VOSK_PATH CGO_CPPFLAGS="-I $VOSK_PATH" CGO_LDFLAGS="-L $VOSK_PATH" go run . -f test.wav
```
for Windows (we place DLLs in current folder where linker finds them):
```
git clone https://github.com/alphacep/vosk-api
cd vosk-api/go/example
wget https://github.com/alphacep/vosk-api/releases/download/v0.3.45/vosk-linux-x86_64-0.3.45.zip
unzip vosk-linux-x86_64-0.3.45.zip
cp vosk-linux-x86_64-0.3.45/*.dll .
cp vosk-linux-x86_64-0.3.45/*.h .
wget https://alphacephei.com/vosk/models/vosk-model-small-en-us-0.15.zip
unzip vosk-model-small-en-us-0.15.zip
mv vosk-model-small-en-us-0.15 model
cp ../../python/example/test.wav .
VOSK_PATH=`pwd` LD_LIBRARY_PATH=$VOSK_PATH CGO_CPPFLAGS="-I $VOSK_PATH" CGO_LDFLAGS="-L $VOSK_PATH -lvosk -lpthread -dl" go run . -f test.wav
```
+1 -1
View File
@@ -1,2 +1,2 @@
// Example package for Vosk Go bindings.
package test_simple
package main
+9 -2
View File
@@ -7,6 +7,7 @@ import (
"io"
"log"
"os"
"encoding/json"
vosk "github.com/alphacep/vosk-api/go"
)
@@ -21,6 +22,9 @@ func main() {
log.Fatal(err)
}
// we can check if word is in the vocabulary
// fmt.Println(model.FindWord("air"))
sampleRate := 16000.0
rec, err := vosk.NewRecognizer(model, sampleRate)
if err != nil {
@@ -48,9 +52,12 @@ func main() {
}
if rec.AcceptWaveform(buf) != 0 {
fmt.Println(string(rec.Result()))
fmt.Println(rec.Result())
}
}
fmt.Println(string(rec.FinalResult()))
// Unmarshal example for final result
var jres map[string]interface{}
json.Unmarshal([]byte(rec.FinalResult()), &jres)
fmt.Println(jres["text"])
}
+26 -16
View File
@@ -5,6 +5,7 @@ package vosk
// #include <stdlib.h>
// #include <vosk_api.h>
import "C"
import "unsafe"
// VoskModel contains a reference to the C VoskModel
type VoskModel struct {
@@ -13,7 +14,9 @@ type VoskModel struct {
// NewModel creates a new VoskModel instance
func NewModel(modelPath string) (*VoskModel, error) {
internal := C.vosk_model_new(C.CString(modelPath))
cmodelPath := C.CString(modelPath)
defer C.free(unsafe.Pointer(cmodelPath))
internal := C.vosk_model_new(cmodelPath)
model := &VoskModel{model: internal}
return model, nil
}
@@ -29,10 +32,10 @@ func freeModel(model *VoskModel) {
// FindWord checks if a word can be recognized by the model.
// Returns the word symbol if the word exists inside the model or
// -1 otherwise.
func (m *VoskModel) FindWord(word []byte) int {
cbuf := C.CBytes(word)
defer C.free(cbuf)
i := C.vosk_model_find_word(m.model, (*C.char)(cbuf))
func (m *VoskModel) FindWord(word string) int {
cstr := C.CString(word)
defer C.free(unsafe.Pointer(cstr))
i := C.vosk_model_find_word(m.model, cstr)
return int(i)
}
@@ -43,7 +46,9 @@ type VoskSpkModel struct {
// NewSpkModel creates a new VoskSpkModel instance
func NewSpkModel(spkModelPath string) (*VoskSpkModel, error) {
internal := C.vosk_spk_model_new(C.CString(spkModelPath))
cspkModelPath := C.CString(spkModelPath)
defer C.free(unsafe.Pointer(cspkModelPath))
internal := C.vosk_spk_model_new(cspkModelPath)
spkModel := &VoskSpkModel{spkModel: internal}
return spkModel, nil
}
@@ -84,10 +89,10 @@ func NewRecognizerSpk(model *VoskModel, sampleRate float64, spkModel *VoskSpkMod
}
// NewRecognizerGrm creates a new VoskRecognizer instance with the phrase list.
func NewRecognizerGrm(model *VoskModel, sampleRate float64, grammer []byte) (*VoskRecognizer, error) {
cbuf := C.CBytes(grammer)
defer C.free(cbuf)
internal := C.vosk_recognizer_new_grm(model.model, C.float(sampleRate), (*C.char)(cbuf))
func NewRecognizerGrm(model *VoskModel, sampleRate float64, grammar string) (*VoskRecognizer, error) {
cgrammar := C.CString(grammar)
defer C.free(unsafe.Pointer(cgrammar))
internal := C.vosk_recognizer_new_grm(model.model, C.float(sampleRate), cgrammar)
rec := &VoskRecognizer{rec: internal}
return rec, nil
}
@@ -107,6 +112,11 @@ func (r *VoskRecognizer) SetWords(words int) {
C.vosk_recognizer_set_words(r.rec, C.int(words))
}
// SetPartialWords enables words with times in the partial ouput.
func (r *VoskRecognizer) SetPartialWords(words int) {
C.vosk_recognizer_set_partial_words(r.rec, C.int(words))
}
// AcceptWaveform accepts and processes a new chunk of the voice data.
func (r *VoskRecognizer) AcceptWaveform(buffer []byte) int {
cbuf := C.CBytes(buffer)
@@ -116,19 +126,19 @@ func (r *VoskRecognizer) AcceptWaveform(buffer []byte) int {
}
// Result returns a speech recognition result.
func (r *VoskRecognizer) Result() []byte {
return []byte(C.GoString(C.vosk_recognizer_result(r.rec)))
func (r *VoskRecognizer) Result() string {
return C.GoString(C.vosk_recognizer_result(r.rec))
}
// PartialResult returns a partial speech recognition result.
func (r *VoskRecognizer) PartialResult() []byte {
return []byte(C.GoString(C.vosk_recognizer_partial_result(r.rec)))
func (r *VoskRecognizer) PartialResult() string {
return C.GoString(C.vosk_recognizer_partial_result(r.rec))
}
// FinalResult returns a speech recognition result. Same as result, but doesn't wait
// for silence.
func (r *VoskRecognizer) FinalResult() []byte {
return []byte(C.GoString(C.vosk_recognizer_final_result(r.rec)))
func (r *VoskRecognizer) FinalResult() string {
return C.GoString(C.vosk_recognizer_final_result(r.rec))
}
// Reset resets the recognizer.
+1 -1
View File
@@ -12,5 +12,5 @@ repositories {
dependencies {
implementation group: 'net.java.dev.jna', name: 'jna', version: '5.7.0'
implementation group: 'com.alphacephei', name: 'vosk', version: '0.3.41+'
implementation group: 'com.alphacephei', name: 'vosk', version: '0.3.40+'
}
+1 -1
View File
@@ -16,7 +16,7 @@ repositories {
archivesBaseName = 'vosk'
group = 'com.alphacephei'
version = '0.3.41'
version = '0.3.45'
mavenPublish {
group = 'com.alphacephei'
+2 -1
View File
@@ -13,7 +13,8 @@ Vosk is an offline open source speech recognition toolkit. It enables
speech recognition for 20+ languages and dialects - English, Indian
English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish,
Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino,
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech. More to come.
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish.
More to come.
Vosk models are small (50 Mb) but provide continuous large vocabulary
transcription, zero-latency response with streaming API, reconfigurable
+11 -4
View File
@@ -18,11 +18,11 @@ const rec = new vosk.Recognizer({model: model, sampleRate: SAMPLE_RATE});
var micInstance = mic({
rate: String(SAMPLE_RATE),
channels: '1',
debug: false
debug: false,
device: 'default',
});
var micInputStream = micInstance.getAudioStream();
micInstance.start();
micInputStream.on('data', data => {
if (rec.acceptWaveform(data))
@@ -31,9 +31,16 @@ micInputStream.on('data', data => {
console.log(rec.partialResult());
});
process.on('SIGINT', function() {
micInputStream.on('audioProcessExitComplete', function() {
console.log("Cleaning up");
console.log(rec.finalResult());
console.log("\nDone");
rec.free();
model.free();
});
process.on('SIGINT', function() {
console.log("\nStopping");
micInstance.stop();
});
micInstance.start();
+1 -1
View File
@@ -72,7 +72,7 @@ if (os.platform() == 'win32') {
// Update path to load dependent dlls
let currentPath = process.env.Path;
let dllDirectory = path.resolve(path.join(__dirname, "lib", "win-x86_64"));
process.env.Path = currentPath + path.delimiter + dllDirectory;
process.env.Path = dllDirectory + path.delimiter + currentPath;
soname = path.join(__dirname, "lib", "win-x86_64", "libvosk.dll")
} else if (os.platform() == 'darwin') {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vosk",
"version": "0.3.41",
"version": "0.3.45",
"description": "Node binding for continuous offline voice recoginition with Vosk library.",
"repository": {
"type": "git",
+639
View File
@@ -0,0 +1,639 @@
[MAIN]
# Analyse import fallback blocks. This can be used to support both Python 2 and
# 3 compatible code, which means that the block might have code that exists
# only in one or another interpreter, leading to false positives when analysed.
analyse-fallback-blocks=no
# Load and enable all available extensions. Use --list-extensions to see a list
# all available extensions.
#enable-all-extensions=
# In error mode, messages with a category besides ERROR or FATAL are
# suppressed, and no reports are done by default. Error mode is compatible with
# disabling specific errors.
#errors-only=
# Always return a 0 (non-error) status code, even if lint errors are found.
# This is primarily useful in continuous integration scripts.
#exit-zero=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-allow-list=
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code. (This is an alternative name to extension-pkg-allow-list
# for backward compatibility.)
extension-pkg-whitelist=
# Return non-zero exit code if any of these messages/categories are detected,
# even if score is above --fail-under value. Syntax same as enable. Messages
# specified are enabled, while categories only check already-enabled messages.
fail-on=
# Specify a score threshold under which the program will exit with error.
fail-under=10
# Interpret the stdin as a python script, whose filename needs to be passed as
# the module_or_package argument.
#from-stdin=
# Files or directories to be skipped. They should be base names, not paths.
ignore=CVS
# Add files or directories matching the regular expressions patterns to the
# ignore-list. The regex matches against paths and can be in Posix or Windows
# format. Because '\' represents the directory delimiter on Windows systems, it
# can't be used as an escape character.
ignore-paths=
# Files or directories matching the regular expression patterns are skipped.
# The regex matches against base names, not paths. The default value ignores
# Emacs file locks
ignore-patterns=^\.#
# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
# and thus existing member attributes cannot be deduced by static analysis). It
# supports qualified module names, as well as Unix pattern matching.
ignored-modules=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
#init-hook=
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the
# number of processors available to use, and will cap the count on Windows to
# avoid hangs.
jobs=1
# Control the amount of potential inferred values when inferring a single
# object. This can help the performance when dealing with large functions or
# complex, nested conditions.
limit-inference-results=100
# List of plugins (as comma separated values of python module names) to load,
# usually to register additional checkers.
load-plugins=
# Pickle collected data for later comparisons.
persistent=yes
# Minimum Python version to use for version dependent checks. Will default to
# the version used to run pylint.
py-version=3.7
# Discover python modules and packages in the file system subtree.
recursive=no
# When enabled, pylint would attempt to guess common misconfiguration and emit
# user-friendly hints instead of false-positive error messages.
suggestion-mode=yes
# Allow loading of arbitrary C extensions. Extensions are imported into the
# active Python interpreter and may run arbitrary code.
unsafe-load-any-extension=no
# In verbose mode, extra non-checker-related info will be displayed.
#verbose=
[REPORTS]
# Python expression which should return a score less than or equal to 10. You
# have access to the variables 'fatal', 'error', 'warning', 'refactor',
# 'convention', and 'info' which contain the number of messages in each
# category, as well as 'statement' which is the total number of statements
# analyzed. This score is used by the global evaluation report (RP0004).
evaluation=max(0, 0 if fatal else 10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10))
# Template used to display messages. This is a python new-style format string
# used to format the message information. See doc for all details.
msg-template=
# Set the output format. Available formats are text, parseable, colorized, json
# and msvs (visual studio). You can also give a reporter class, e.g.
# mypackage.mymodule.MyReporterClass.
#output-format=
# Tells whether to display a full report or only the messages.
reports=no
# Activate the evaluation score.
score=yes
[MESSAGES CONTROL]
# Only show warnings with the listed confidence levels. Leave empty to show
# all. Valid levels: HIGH, CONTROL_FLOW, INFERENCE, INFERENCE_FAILURE,
# UNDEFINED.
confidence=HIGH,
CONTROL_FLOW,
INFERENCE,
INFERENCE_FAILURE,
UNDEFINED
# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once). You can also use "--disable=all" to
# disable everything first and then re-enable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use "--disable=all --enable=classes
# --disable=W".
disable=raw-checker-failed,
bad-inline-option,
locally-disabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
use-symbolic-message-instead,
missing-module-docstring, # added
missing-class-docstring, # added
missing-function-docstring, # added
invalid-name, # added
broad-except, # added
wrong-import-order, # added
consider-using-f-string, # added
logging-format-interpolation, # added
no-member, # added
consider-using-with, # added
unused-argument,
no-else-return, # added
too-few-public-methods, # added
import-error, # added
protected-access, # added
unused-variable, # added
R0801 # added (similarity of two scripts)
# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once). See also the "--disable" option for examples.
enable=c-extension-no-member
[BASIC]
# Naming style matching correct argument names.
argument-naming-style=snake_case
# Regular expression matching correct argument names. Overrides argument-
# naming-style. If left empty, argument names will be checked with the set
# naming style.
#argument-rgx=
# Naming style matching correct attribute names.
attr-naming-style=snake_case
# Regular expression matching correct attribute names. Overrides attr-naming-
# style. If left empty, attribute names will be checked with the set naming
# style.
#attr-rgx=
# Bad variable names which should always be refused, separated by a comma.
bad-names=foo,
bar,
baz,
toto,
tutu,
tata
# Bad variable names regexes, separated by a comma. If names match any regex,
# they will always be refused
bad-names-rgxs=
# Naming style matching correct class attribute names.
class-attribute-naming-style=any
# Regular expression matching correct class attribute names. Overrides class-
# attribute-naming-style. If left empty, class attribute names will be checked
# with the set naming style.
#class-attribute-rgx=
# Naming style matching correct class constant names.
class-const-naming-style=UPPER_CASE
# Regular expression matching correct class constant names. Overrides class-
# const-naming-style. If left empty, class constant names will be checked with
# the set naming style.
#class-const-rgx=
# Naming style matching correct class names.
class-naming-style=PascalCase
# Regular expression matching correct class names. Overrides class-naming-
# style. If left empty, class names will be checked with the set naming style.
#class-rgx=
# Naming style matching correct constant names.
const-naming-style=UPPER_CASE
# Regular expression matching correct constant names. Overrides const-naming-
# style. If left empty, constant names will be checked with the set naming
# style.
#const-rgx=
# Minimum line length for functions/classes that require docstrings, shorter
# ones are exempt.
docstring-min-length=-1
# Naming style matching correct function names.
function-naming-style=snake_case
# Regular expression matching correct function names. Overrides function-
# naming-style. If left empty, function names will be checked with the set
# naming style.
#function-rgx=
# Good variable names which should always be accepted, separated by a comma.
good-names=i,
j,
k,
ex,
Run,
_,
x,
y,
nx,
ny
# Good variable names regexes, separated by a comma. If names match any regex,
# they will always be accepted
good-names-rgxs=
# Include a hint for the correct naming format with invalid-name.
include-naming-hint=no
# Naming style matching correct inline iteration names.
inlinevar-naming-style=any
# Regular expression matching correct inline iteration names. Overrides
# inlinevar-naming-style. If left empty, inline iteration names will be checked
# with the set naming style.
#inlinevar-rgx=
# Naming style matching correct method names.
method-naming-style=snake_case
# Regular expression matching correct method names. Overrides method-naming-
# style. If left empty, method names will be checked with the set naming style.
#method-rgx=
# Naming style matching correct module names.
module-naming-style=snake_case
# Regular expression matching correct module names. Overrides module-naming-
# style. If left empty, module names will be checked with the set naming style.
#module-rgx=
# Colon-delimited sets of names that determine each other's naming style when
# the name regexes allow several styles.
name-group=
# Regular expression which should only match function or class names that do
# not require a docstring.
no-docstring-rgx=^_
# List of decorators that produce properties, such as abc.abstractproperty. Add
# to this list to register other decorators that produce valid properties.
# These decorators are taken in consideration only for invalid-name.
property-classes=abc.abstractproperty
# Regular expression matching correct type variable names. If left empty, type
# variable names will be checked with the set naming style.
#typevar-rgx=
# Naming style matching correct variable names.
variable-naming-style=snake_case
# Regular expression matching correct variable names. Overrides variable-
# naming-style. If left empty, variable names will be checked with the set
# naming style.
#variable-rgx=
[VARIABLES]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid defining new builtins when possible.
additional-builtins=
# Tells whether unused global variables should be treated as a violation.
allow-global-unused-variables=yes
# List of names allowed to shadow builtins
allowed-redefined-builtins=
# List of strings which can identify a callback function by name. A callback
# name must start or end with one of those strings.
callbacks=cb_,
_cb
# A regular expression matching the name of dummy variables (i.e. expected to
# not be used).
dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
# Argument names that match this expression will be ignored.
ignored-argument-names=_.*|^ignored_|^unused_
# Tells whether we should check for unused import in __init__ files.
init-import=no
# List of qualified module names which can have objects that can redefine
# builtins.
redefining-builtins-modules=six.moves,past.builtins,future.builtins,builtins,io
[SIMILARITIES]
# Comments are removed from the similarity computation
ignore-comments=yes
# Docstrings are removed from the similarity computation
ignore-docstrings=yes
# Imports are removed from the similarity computation
ignore-imports=yes
# Signatures are removed from the similarity computation
ignore-signatures=yes
# Minimum lines number of a similarity.
min-similarity-lines=4
[MISCELLANEOUS]
# List of note tags to take in consideration, separated by a comma.
notes=FIXME,
XXX,
TODO
# Regular expression of note tags to take in consideration.
notes-rgx=
[STRING]
# This flag controls whether inconsistent-quotes generates a warning when the
# character used as a quote delimiter is used inconsistently within a module.
check-quote-consistency=no
# This flag controls whether the implicit-str-concat should generate a warning
# on implicit string concatenation in sequences defined over several lines.
check-str-concat-over-line-jumps=no
[IMPORTS]
# List of modules that can be imported at any level, not just the top level
# one.
allow-any-import-level=
# Allow wildcard imports from modules that define __all__.
allow-wildcard-with-all=no
# Deprecated modules which should not be used, separated by a comma.
deprecated-modules=
# Output a graph (.gv or any supported image format) of external dependencies
# to the given file (report RP0402 must not be disabled).
ext-import-graph=
# Output a graph (.gv or any supported image format) of all (i.e. internal and
# external) dependencies to the given file (report RP0402 must not be
# disabled).
import-graph=
# Output a graph (.gv or any supported image format) of internal dependencies
# to the given file (report RP0402 must not be disabled).
int-import-graph=
# Force import order to recognize a module as part of the standard
# compatibility libraries.
known-standard-library=
# Force import order to recognize a module as part of a third party library.
known-third-party=enchant
# Couples of modules and preferred modules, separated by a comma.
preferred-modules=
[EXCEPTIONS]
# Exceptions that will emit a warning when caught.
overgeneral-exceptions=BaseException,
Exception
[DESIGN]
# List of regular expressions of class ancestor names to ignore when counting
# public methods (see R0903)
exclude-too-few-public-methods=
# List of qualified class names to ignore when counting class parents (see
# R0901)
ignored-parents=
# Maximum number of arguments for function / method.
max-args=5
# Maximum number of attributes for a class (see R0902).
max-attributes=7
# Maximum number of boolean expressions in an if statement (see R0916).
max-bool-expr=5
# Maximum number of branch for function / method body.
max-branches=12
# Maximum number of locals for function / method body.
max-locals=15
# Maximum number of parents for a class (see R0901).
max-parents=7
# Maximum number of public methods for a class (see R0904).
max-public-methods=20
# Maximum number of return / yield for function / method body.
max-returns=6
# Maximum number of statements in function / method body.
max-statements=50
# Minimum number of public methods for a class (see R0903).
min-public-methods=2
[METHOD_ARGS]
# List of qualified names (i.e., library.method) which require a timeout
# parameter e.g. 'requests.api.get,requests.api.post'
timeout-methods=requests.api.delete,requests.api.get,requests.api.head,requests.api.options,requests.api.patch,requests.api.post,requests.api.put,requests.api.request
[LOGGING]
# The type of string formatting that logging methods do. `old` means using %
# formatting, `new` is for `{}` formatting.
logging-format-style=old
# Logging modules to check that the string format arguments are in logging
# function parameter format.
logging-modules=logging
[FORMAT]
# Expected format of line ending, e.g. empty (any line ending), LF or CRLF.
expected-line-ending-format=
# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
# Number of spaces of indent required inside a hanging or continued line.
indent-after-paren=4
# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1
# tab).
indent-string=' '
# Maximum number of characters on a single line.
max-line-length=100
# Maximum number of lines in a module.
max-module-lines=1000
# Allow the body of a class to be on the same line as the declaration if body
# contains single statement.
single-line-class-stmt=no
# Allow the body of an if to be on the same line as the test if there is no
# else.
single-line-if-stmt=no
[REFACTORING]
# Maximum number of nested blocks for function / method body
max-nested-blocks=5
# Complete name of functions that never returns. When checking for
# inconsistent-return-statements if a never returning function is called then
# it will be considered as an explicit return statement and no message will be
# printed.
never-returning-functions=sys.exit,argparse.parse_error
[TYPECHECK]
# List of decorators that produce context managers, such as
# contextlib.contextmanager. Add to this list to register other decorators that
# produce valid context managers.
contextmanager-decorators=contextlib.contextmanager
# List of members which are set dynamically and missed by pylint inference
# system, and so shouldn't trigger E1101 when accessed. Python regular
# expressions are accepted.
generated-members=
# Tells whether to warn about missing members when the owner of the attribute
# is inferred to be None.
ignore-none=yes
# This flag controls whether pylint should warn about no-member and similar
# checks whenever an opaque object is returned when inferring. The inference
# can return multiple potential results while evaluating a Python object, but
# some branches might not be evaluated, which results in partial inference. In
# that case, it might be useful to still emit no-member and other checks for
# the rest of the inferred objects.
ignore-on-opaque-inference=yes
# List of symbolic message names to ignore for Mixin members.
ignored-checks-for-mixins=no-member,
not-async-context-manager,
not-context-manager,
attribute-defined-outside-init
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local,argparse.Namespace
# Show a hint with possible names when a member name was not found. The aspect
# of finding the hint is based on edit distance.
missing-member-hint=yes
# The minimum edit distance a name should have in order to be considered a
# similar match for a missing member name.
missing-member-hint-distance=1
# The total number of similar names that should be taken in consideration when
# showing a hint for a missing member.
missing-member-max-choices=1
# Regex pattern to define which classes are considered mixins.
mixin-class-rgx=.*[Mm]ixin
# List of decorators that change the signature of a decorated function.
signature-mutators=
[CLASSES]
# Warn about protected attribute access inside special methods
check-protected-access-in-special-methods=no
# List of method names used to declare (i.e. assign) instance attributes.
defining-attr-methods=__init__,
__new__,
setUp,
__post_init__
# List of member names, which should be excluded from the protected access
# warning.
exclude-protected=_asdict,
_fields,
_replace,
_source,
_make
# List of valid names for the first argument in a class method.
valid-classmethod-first-arg=cls
# List of valid names for the first argument in a metaclass class method.
valid-metaclass-classmethod-first-arg=cls
[SPELLING]
# Limits count of emitted suggestions for spelling mistakes.
max-spelling-suggestions=4
# Spelling dictionary name. Available dictionaries: none. To make it work,
# install the 'python-enchant' package.
spelling-dict=
# List of comma separated words that should be considered directives if they
# appear at the beginning of a comment and should not be checked.
spelling-ignore-comment-directives=fmt: on,fmt: off,noqa:,noqa,nosec,isort:skip,mypy:
# List of comma separated words that should not be checked.
spelling-ignore-words=
# A path to a file that contains the private dictionary; one word per line.
spelling-private-dict-file=
# Tells whether to store unknown words to the private dictionary (see the
# --spelling-private-dict-file option) instead of raising a message.
spelling-store-unknown-words=no
+2 -1
View File
@@ -4,7 +4,8 @@ Vosk is an offline open source speech recognition toolkit. It enables
speech recognition for 20+ languages and dialects - English, Indian
English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish,
Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino,
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech. More to come.
Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish.
More to come.
Vosk models are small (50 Mb) but provide continuous large vocabulary
transcription, zero-latency response with streaming API, reconfigurable
File diff suppressed because one or more lines are too long
+558
View File
@@ -0,0 +1,558 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Vosk Adaptation",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "URzWMmv50-Ba",
"outputId": "0e096a99-74dd-42e2-efb1-9cba784c3664"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/content\n",
"--2022-08-17 09:48:52-- https://alphacephei.com/vosk-colab/kaldi.tar.gz\n",
"Resolving alphacephei.com (alphacephei.com)... 188.40.21.16, 2a01:4f8:13a:279f::2\n",
"Connecting to alphacephei.com (alphacephei.com)|188.40.21.16|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 809174554 (772M) [application/octet-stream]\n",
"Saving to: kaldi.tar.gz\n",
"\n",
"kaldi.tar.gz 100%[===================>] 771.69M 20.3MB/s in 40s \n",
"\n",
"2022-08-17 09:49:33 (19.4 MB/s) - kaldi.tar.gz saved [809174554/809174554]\n",
"\n"
]
}
],
"source": [
"%cd /content\n",
"!wget -c https://alphacephei.com/vosk-colab/kaldi.tar.gz\n",
"!tar xzf kaldi.tar.gz"
]
},
{
"cell_type": "code",
"source": [
"%cd /content/kaldi/egs/ac\n",
"!wget -c https://alphacephei.com/vosk-colab/vosk-model-small-en-us-0.15-compile-colab.tar.gz\n",
"!rm -rf vosk-model-small-en-us-0.15-compile-colab\n",
"!tar xf vosk-model-small-en-us-0.15-compile-colab.tar.gz"
],
"metadata": {
"id": "-065p7WC2SHh",
"colab": {
"base_uri": "https://localhost:8080/"
},
"outputId": "241c7473-7464-48d5-b48d-dc6e3bf4971d"
},
"execution_count": 8,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/content/kaldi/egs/ac\n",
"--2022-08-17 10:28:26-- https://alphacephei.com/vosk-colab/vosk-model-small-en-us-0.15-compile-colab.tar.gz\n",
"Resolving alphacephei.com (alphacephei.com)... 188.40.21.16, 2a01:4f8:13a:279f::2\n",
"Connecting to alphacephei.com (alphacephei.com)|188.40.21.16|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 59618100 (57M) [application/octet-stream]\n",
"Saving to: vosk-model-small-en-us-0.15-compile-colab.tar.gz\n",
"\n",
"vosk-model-small-en 100%[===================>] 56.86M 18.6MB/s in 3.6s \n",
"\n",
"2022-08-17 10:28:30 (15.7 MB/s) - vosk-model-small-en-us-0.15-compile-colab.tar.gz saved [59618100/59618100]\n",
"\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"%cd /content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab\n",
"!ls\n",
"!cat compile-graph.sh\n",
"!bash compile-graph.sh"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wuDjvNbd2sf9",
"outputId": "34a1d2fe-d443-4574-e25d-824e38eb3a78"
},
"execution_count": 9,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab\n",
"compile-graph.sh data_test decode.sh\texp\t local path.sh steps\n",
"conf\t\t db\t dict.py\tget_vocab.py mfcc RESULTS utils\n",
"#!/bin/bash\n",
"\n",
"set -x\n",
"\n",
". path.sh\n",
"\n",
"pip3 install phonetisaurus\n",
"\n",
"rm -rf data\n",
"rm -rf exp/tdnn/lgraph\n",
"rm -rf exp/tdnn/lgraph_orig\n",
"\n",
"mkdir -p data/dict\n",
"cp db/phone/* data/dict\n",
"./dict.py > data/dict/lexicon.txt\n",
"\n",
"python3 ./get_vocab.py > data/mix.vocab\n",
"ngramsymbols data/mix.vocab data/mix.syms\n",
"farcompilestrings --fst_type=compact --symbols=data/mix.syms --keep_symbols --unknown_symbol=\"[unk]\" db/extra.txt data/extra.far\n",
"ngramcount --order=3 data/extra.far - |\n",
" ngramprint --integers | grep -v \"<unk>\" | ngramread |\n",
" ngramshrink --method=count_prune --count_pattern=\"3+:3\" |\n",
" ngrammake --method=witten_bell - data/extra.mod\n",
"gunzip -c db/en-50k-0.4-android.lm.gz | ngramread --renormalize_arpa --ARPA --symbols=data/mix.syms - data/en-us.mod\n",
"ngrammerge --method=\"bayes_model_merge\" --normalize --alpha=0.95 --beta=0.05 data/en-us.mod data/extra.mod data/en-us-mix.mod\n",
"ngramprint --ARPA data/en-us-mix.mod | gzip -c > data/en-us-mix.lm.gz\n",
"\n",
"# Prune for the first stage if needed\n",
"# ngramshrink --method=relative_entropy --theta=2e-8 data/en-us-mix.mod data/en-us-mix-prune.mod\n",
"# ngramprint --ARPA data/en-us-mix-prune.mod | gzip -c > data/en-us-mix-small.lm.gz\n",
"\n",
"utils/prepare_lang.sh data/dict \"[unk]\" data/lang_local data/lang\n",
"utils/format_lm.sh data/lang db/en-50k-0.4-android.lm.gz data/dict/lexicon.txt data/lang_test\n",
"utils/format_lm.sh data/lang data/en-us-mix.lm.gz data/dict/lexicon.txt data/lang_test_adapt\n",
"\n",
"utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test exp/tdnn exp/tdnn/graph\n",
"utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test_adapt exp/tdnn exp/tdnn/graph_adapt\n",
"\n",
"# Lookahead part goes OOM\n",
"#utils/mkgraph_lookahead.sh \\\n",
"# --self-loop-scale 1.0 data/lang \\\n",
"# exp/tdnn data/en-us-mix.lm.gz exp/tdnn/lgraph\n",
"#utils/mkgraph_lookahead.sh \\\n",
"# --self-loop-scale 1.0 data/lang \\\n",
"# exp/tdnn db/en-50k-0.4-android.lm.gz exp/tdnn/lgraph_orig\n",
"+ . path.sh\n",
"+++ pwd\n",
"++ export KALDI_ROOT=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../..\n",
"++ KALDI_ROOT=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../..\n",
"++ export PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/utils:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fstbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/gmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/featbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lm:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmm2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/latbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnetbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/online2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/ivectorbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/chainbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet3bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/sph2pipe_v2.5\n",
"++ PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/utils:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fstbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/gmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/featbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lm:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmm2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/latbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnetbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/online2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/ivectorbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/chainbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet3bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/sph2pipe_v2.5\n",
"++ export PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/ngram-1.3.7/src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/utils:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fstbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/gmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/featbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lm:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmm2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/latbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnetbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/online2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/ivectorbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/chainbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet3bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/sph2pipe_v2.5\n",
"++ PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/ngram-1.3.7/src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/utils:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fstbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/gmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/featbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lm:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/sgmm2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/fgmmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/latbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnetbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/online2bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/ivectorbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/lmbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/chainbin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../src/nnet3bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab:/opt/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/sph2pipe_v2.5\n",
"++ export LD_LIBRARY_PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/lib/fst/\n",
"++ LD_LIBRARY_PATH=/content/kaldi/egs/ac/vosk-model-small-en-us-0.15-compile-colab/../../../tools/openfst/lib/fst/\n",
"++ export LC_ALL=C\n",
"++ LC_ALL=C\n",
"+ pip3 install phonetisaurus\n",
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
"Requirement already satisfied: phonetisaurus in /usr/local/lib/python3.7/dist-packages (0.3.0)\n",
"+ rm -rf data\n",
"+ rm -rf exp/tdnn/lgraph\n",
"+ rm -rf exp/tdnn/lgraph_orig\n",
"+ mkdir -p data/dict\n",
"+ cp db/phone/extra_questions.txt db/phone/nonsilence_phones.txt db/phone/optional_silence.txt db/phone/silence_phones.txt data/dict\n",
"+ ./dict.py\n",
"+ python3 ./get_vocab.py\n",
"+ ngramsymbols data/mix.vocab data/mix.syms\n",
"+ farcompilestrings --fst_type=compact --symbols=data/mix.syms --keep_symbols '--unknown_symbol=[unk]' db/extra.txt data/extra.far\n",
"+ ngramcount --order=3 data/extra.far -\n",
"+ ngrammake --method=witten_bell - data/extra.mod\n",
"+ ngramshrink --method=count_prune --count_pattern=3+:3\n",
"+ ngramread\n",
"+ ngramprint --integers\n",
"+ grep -v '<unk>'\n",
"+ ngramread --renormalize_arpa --ARPA --symbols=data/mix.syms - data/en-us.mod\n",
"+ gunzip -c db/en-50k-0.4-android.lm.gz\n",
"+ ngrammerge --method=bayes_model_merge --normalize --alpha=0.95 --beta=0.05 data/en-us.mod data/extra.mod data/en-us-mix.mod\n",
"+ ngramprint --ARPA data/en-us-mix.mod\n",
"+ gzip -c\n",
"+ utils/prepare_lang.sh data/dict '[unk]' data/lang_local data/lang\n",
"utils/prepare_lang.sh data/dict [unk] data/lang_local data/lang\n",
"Checking data/dict/silence_phones.txt ...\n",
"--> reading data/dict/silence_phones.txt\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/dict/silence_phones.txt is OK\n",
"\n",
"Checking data/dict/optional_silence.txt ...\n",
"--> reading data/dict/optional_silence.txt\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/dict/optional_silence.txt is OK\n",
"\n",
"Checking data/dict/nonsilence_phones.txt ...\n",
"--> reading data/dict/nonsilence_phones.txt\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/dict/nonsilence_phones.txt is OK\n",
"\n",
"Checking disjoint: silence_phones.txt, nonsilence_phones.txt\n",
"--> disjoint property is OK.\n",
"\n",
"Checking data/dict/lexicon.txt\n",
"--> reading data/dict/lexicon.txt\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/dict/lexicon.txt is OK\n",
"\n",
"Checking data/dict/extra_questions.txt ...\n",
"--> data/dict/extra_questions.txt is empty (this is OK)\n",
"--> SUCCESS [validating dictionary directory data/dict]\n",
"\n",
"**Creating data/dict/lexiconp.txt from data/dict/lexicon.txt\n",
"fstaddselfloops data/lang/phones/wdisambig_phones.int data/lang/phones/wdisambig_words.int \n",
"prepare_lang.sh: validating output directory\n",
"utils/validate_lang.pl data/lang\n",
"Checking existence of separator file\n",
"separator file data/lang/subword_separator.txt is empty or does not exist, deal in word case.\n",
"Checking data/lang/phones.txt ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/lang/phones.txt is OK\n",
"\n",
"Checking words.txt: #0 ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> data/lang/words.txt is OK\n",
"\n",
"Checking disjoint: silence.txt, nonsilence.txt, disambig.txt ...\n",
"--> silence.txt and nonsilence.txt are disjoint\n",
"--> silence.txt and disambig.txt are disjoint\n",
"--> disambig.txt and nonsilence.txt are disjoint\n",
"--> disjoint property is OK\n",
"\n",
"Checking sumation: silence.txt, nonsilence.txt, disambig.txt ...\n",
"--> found no unexplainable phones in phones.txt\n",
"\n",
"Checking data/lang/phones/context_indep.{txt, int, csl} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 10 entry/entries in data/lang/phones/context_indep.txt\n",
"--> data/lang/phones/context_indep.int corresponds to data/lang/phones/context_indep.txt\n",
"--> data/lang/phones/context_indep.csl corresponds to data/lang/phones/context_indep.txt\n",
"--> data/lang/phones/context_indep.{txt, int, csl} are OK\n",
"\n",
"Checking data/lang/phones/nonsilence.{txt, int, csl} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 156 entry/entries in data/lang/phones/nonsilence.txt\n",
"--> data/lang/phones/nonsilence.int corresponds to data/lang/phones/nonsilence.txt\n",
"--> data/lang/phones/nonsilence.csl corresponds to data/lang/phones/nonsilence.txt\n",
"--> data/lang/phones/nonsilence.{txt, int, csl} are OK\n",
"\n",
"Checking data/lang/phones/silence.{txt, int, csl} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 10 entry/entries in data/lang/phones/silence.txt\n",
"--> data/lang/phones/silence.int corresponds to data/lang/phones/silence.txt\n",
"--> data/lang/phones/silence.csl corresponds to data/lang/phones/silence.txt\n",
"--> data/lang/phones/silence.{txt, int, csl} are OK\n",
"\n",
"Checking data/lang/phones/optional_silence.{txt, int, csl} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 1 entry/entries in data/lang/phones/optional_silence.txt\n",
"--> data/lang/phones/optional_silence.int corresponds to data/lang/phones/optional_silence.txt\n",
"--> data/lang/phones/optional_silence.csl corresponds to data/lang/phones/optional_silence.txt\n",
"--> data/lang/phones/optional_silence.{txt, int, csl} are OK\n",
"\n",
"Checking data/lang/phones/disambig.{txt, int, csl} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 14 entry/entries in data/lang/phones/disambig.txt\n",
"--> data/lang/phones/disambig.int corresponds to data/lang/phones/disambig.txt\n",
"--> data/lang/phones/disambig.csl corresponds to data/lang/phones/disambig.txt\n",
"--> data/lang/phones/disambig.{txt, int, csl} are OK\n",
"\n",
"Checking data/lang/phones/roots.{txt, int} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 41 entry/entries in data/lang/phones/roots.txt\n",
"--> data/lang/phones/roots.int corresponds to data/lang/phones/roots.txt\n",
"--> data/lang/phones/roots.{txt, int} are OK\n",
"\n",
"Checking data/lang/phones/sets.{txt, int} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 41 entry/entries in data/lang/phones/sets.txt\n",
"--> data/lang/phones/sets.int corresponds to data/lang/phones/sets.txt\n",
"--> data/lang/phones/sets.{txt, int} are OK\n",
"\n",
"Checking data/lang/phones/extra_questions.{txt, int} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 9 entry/entries in data/lang/phones/extra_questions.txt\n",
"--> data/lang/phones/extra_questions.int corresponds to data/lang/phones/extra_questions.txt\n",
"--> data/lang/phones/extra_questions.{txt, int} are OK\n",
"\n",
"Checking data/lang/phones/word_boundary.{txt, int} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 166 entry/entries in data/lang/phones/word_boundary.txt\n",
"--> data/lang/phones/word_boundary.int corresponds to data/lang/phones/word_boundary.txt\n",
"--> data/lang/phones/word_boundary.{txt, int} are OK\n",
"\n",
"Checking optional_silence.txt ...\n",
"--> reading data/lang/phones/optional_silence.txt\n",
"--> data/lang/phones/optional_silence.txt is OK\n",
"\n",
"Checking disambiguation symbols: #0 and #1\n",
"--> data/lang/phones/disambig.txt has \"#0\" and \"#1\"\n",
"--> data/lang/phones/disambig.txt is OK\n",
"\n",
"Checking topo ...\n",
"\n",
"Checking word_boundary.txt: silence.txt, nonsilence.txt, disambig.txt ...\n",
"--> data/lang/phones/word_boundary.txt doesn't include disambiguation symbols\n",
"--> data/lang/phones/word_boundary.txt is the union of nonsilence.txt and silence.txt\n",
"--> data/lang/phones/word_boundary.txt is OK\n",
"\n",
"Checking word-level disambiguation symbols...\n",
"--> data/lang/phones/wdisambig.txt exists (newer prepare_lang.sh)\n",
"Checking word_boundary.int and disambig.int\n",
"--> generating a 98 word/subword sequence\n",
"--> resulting phone sequence from L.fst corresponds to the word sequence\n",
"--> L.fst is OK\n",
"--> generating a 49 word/subword sequence\n",
"--> resulting phone sequence from L_disambig.fst corresponds to the word sequence\n",
"--> L_disambig.fst is OK\n",
"\n",
"Checking data/lang/oov.{txt, int} ...\n",
"--> text seems to be UTF-8 or ASCII, checking whitespaces\n",
"--> text contains only allowed whitespaces\n",
"--> 1 entry/entries in data/lang/oov.txt\n",
"--> data/lang/oov.int corresponds to data/lang/oov.txt\n",
"--> data/lang/oov.{txt, int} are OK\n",
"\n",
"--> data/lang/L.fst is olabel sorted\n",
"--> data/lang/L_disambig.fst is olabel sorted\n",
"--> SUCCESS [validating lang directory data/lang]\n",
"+ utils/format_lm.sh data/lang db/en-50k-0.4-android.lm.gz data/dict/lexicon.txt data/lang_test\n",
"Converting 'db/en-50k-0.4-android.lm.gz' to FST\n",
"arpa2fst --disambig-symbol=#0 --read-symbol-table=data/lang_test/words.txt - data/lang_test/G.fst \n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:94) Reading \\data\\ section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\1-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\2-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\3-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:RemoveRedundantStates():arpa-lm-compiler.cc:359) Reduced num-states from 1217362 to 185036\n",
"fstisstochastic data/lang_test/G.fst \n",
"0.476411 -3.03779\n",
"Succeeded in formatting LM: 'db/en-50k-0.4-android.lm.gz'\n",
"+ utils/format_lm.sh data/lang data/en-us-mix.lm.gz data/dict/lexicon.txt data/lang_test_adapt\n",
"Converting 'data/en-us-mix.lm.gz' to FST\n",
"arpa2fst --disambig-symbol=#0 --read-symbol-table=data/lang_test_adapt/words.txt - data/lang_test_adapt/G.fst \n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:94) Reading \\data\\ section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\1-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\2-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:Read():arpa-file-parser.cc:149) Reading \\3-grams: section.\n",
"LOG (arpa2fst[5.5.1046~1-76cd5]:RemoveRedundantStates():arpa-lm-compiler.cc:359) Reduced num-states from 1217646 to 185095\n",
"fstisstochastic data/lang_test_adapt/G.fst \n",
"6.81902e-07 -3.03779\n",
"Succeeded in formatting LM: 'data/en-us-mix.lm.gz'\n",
"+ utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test exp/tdnn exp/tdnn/graph\n",
"tree-info exp/tdnn/tree \n",
"tree-info exp/tdnn/tree \n",
"fstdeterminizestar --use-log=true \n",
"fsttablecompose data/lang_test/L_disambig.fst data/lang_test/G.fst \n",
"fstminimizeencoded \n",
"fstpushspecial \n",
"fstisstochastic data/lang_test/tmp/LG.fst \n",
"-0.145498 -0.146281\n",
"[info]: LG not stochastic.\n",
"fstcomposecontext --context-size=2 --central-position=1 --read-disambig-syms=data/lang_test/phones/disambig.int --write-disambig-syms=data/lang_test/tmp/disambig_ilabels_2_1.int data/lang_test/tmp/ilabels_2_1.905 data/lang_test/tmp/LG.fst \n",
"fstisstochastic data/lang_test/tmp/CLG_2_1.fst \n",
"-0.145498 -0.146281\n",
"[info]: CLG not stochastic.\n",
"make-h-transducer --disambig-syms-out=exp/tdnn/graph/disambig_tid.int --transition-scale=1.0 data/lang_test/tmp/ilabels_2_1 exp/tdnn/tree exp/tdnn/final.mdl \n",
"fstrmepslocal \n",
"fsttablecompose exp/tdnn/graph/Ha.fst data/lang_test/tmp/CLG_2_1.fst \n",
"fstdeterminizestar --use-log=true \n",
"fstminimizeencoded \n",
"fstrmsymbols exp/tdnn/graph/disambig_tid.int \n",
"fstisstochastic exp/tdnn/graph/HCLGa.fst \n",
"-0.109817 -0.571742\n",
"HCLGa is not stochastic\n",
"add-self-loops --self-loop-scale=1.0 --reorder=true exp/tdnn/final.mdl exp/tdnn/graph/HCLGa.fst \n",
"fstisstochastic exp/tdnn/graph/HCLG.fst \n",
"1.90465e-09 -0.415046\n",
"[info]: final HCLG is not stochastic.\n",
"+ utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test_adapt exp/tdnn exp/tdnn/graph_adapt\n",
"tree-info exp/tdnn/tree \n",
"tree-info exp/tdnn/tree \n",
"fstdeterminizestar --use-log=true \n",
"fsttablecompose data/lang_test_adapt/L_disambig.fst data/lang_test_adapt/G.fst \n",
"fstminimizeencoded \n",
"fstpushspecial \n",
"fstisstochastic data/lang_test_adapt/tmp/LG.fst \n",
"-0.148474 -0.149181\n",
"[info]: LG not stochastic.\n",
"fstcomposecontext --context-size=2 --central-position=1 --read-disambig-syms=data/lang_test_adapt/phones/disambig.int --write-disambig-syms=data/lang_test_adapt/tmp/disambig_ilabels_2_1.int data/lang_test_adapt/tmp/ilabels_2_1.979 data/lang_test_adapt/tmp/LG.fst \n",
"fstisstochastic data/lang_test_adapt/tmp/CLG_2_1.fst \n",
"-0.148474 -0.149181\n",
"[info]: CLG not stochastic.\n",
"make-h-transducer --disambig-syms-out=exp/tdnn/graph_adapt/disambig_tid.int --transition-scale=1.0 data/lang_test_adapt/tmp/ilabels_2_1 exp/tdnn/tree exp/tdnn/final.mdl \n",
"fstrmepslocal \n",
"fsttablecompose exp/tdnn/graph_adapt/Ha.fst data/lang_test_adapt/tmp/CLG_2_1.fst \n",
"fstdeterminizestar --use-log=true \n",
"fstminimizeencoded \n",
"fstrmsymbols exp/tdnn/graph_adapt/disambig_tid.int \n",
"fstisstochastic exp/tdnn/graph_adapt/HCLGa.fst \n",
"-0.113907 -0.5857\n",
"HCLGa is not stochastic\n",
"add-self-loops --self-loop-scale=1.0 --reorder=true exp/tdnn/final.mdl exp/tdnn/graph_adapt/HCLGa.fst \n",
"fstisstochastic exp/tdnn/graph_adapt/HCLG.fst \n",
"1.90465e-09 -0.423618\n",
"[info]: final HCLG is not stochastic.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!cat decode.sh\n",
"!bash decode.sh"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Sl3QBI1MXpc-",
"outputId": "affac8a3-782f-4000-e31f-81bfed47a37a"
},
"execution_count": 10,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"#!/bin/bash\n",
"\n",
". path.sh\n",
"\n",
"steps/make_mfcc.sh --nj 10 data_test/test_small exp/make_mfcc/test mfcc\n",
"steps/compute_cmvn_stats.sh data_test/test_small exp/make_mfcc/test mfcc\n",
"utils/fix_data_dir.sh data_test/test_small\n",
"\n",
"steps/online/nnet2/extract_ivectors_online.sh --nj 4 \\\n",
" data_test/test_small exp/extractor \\\n",
" exp/ivectors_test\n",
"\n",
"steps/nnet3/decode.sh --nj 4 \\\n",
" --acwt 1.0 --post-decode-acwt 10.0 \\\n",
" --online-ivector-dir exp/ivectors_test \\\n",
" exp/tdnn/graph_adapt data_test/test_small exp/tdnn/decode_test_adapt\n",
"\n",
"steps/nnet3/decode.sh --nj 4 \\\n",
" --acwt 1.0 --post-decode-acwt 10.0 \\\n",
" --online-ivector-dir exp/ivectors_test \\\n",
" exp/tdnn/graph data_test/test_small exp/tdnn/decode_test\n",
"\n",
"#steps/nnet3/decode_lookahead.sh --nj 4 \\\n",
"# --acwt 1.0 --post-decode-acwt 10.0 \\\n",
"# --online-ivector-dir exp/ivectors_test \\\n",
"# exp/tdnn/lgraph data_test/test_small exp/tdnn/decode_test_adapt\n",
"#steps/nnet3/decode_lookahead.sh --nj 4 \\\n",
"# --acwt 1.0 --post-decode-acwt 10.0 \\\n",
"# --online-ivector-dir exp/ivectors_test \\\n",
"# exp/tdnn/lgraph_orig data_test/test_small exp/tdnn/decode_test\n",
"steps/make_mfcc.sh --nj 10 data_test/test_small exp/make_mfcc/test mfcc\n",
"steps/make_mfcc.sh: moving data_test/test_small/feats.scp to data_test/test_small/.backup\n",
"utils/validate_data_dir.sh: Successfully validated data-directory data_test/test_small\n",
"steps/make_mfcc.sh: [info]: no segments file exists: assuming wav.scp indexed by utterance.\n",
"steps/make_mfcc.sh: Succeeded creating MFCC features for test_small\n",
"steps/compute_cmvn_stats.sh data_test/test_small exp/make_mfcc/test mfcc\n",
"Succeeded creating CMVN stats for test_small\n",
"fix_data_dir.sh: kept all 50 utterances.\n",
"fix_data_dir.sh: old files are kept in data_test/test_small/.backup\n",
"steps/online/nnet2/extract_ivectors_online.sh --nj 4 data_test/test_small exp/extractor exp/ivectors_test\n",
"steps/online/nnet2/extract_ivectors_online.sh: extracting iVectors\n",
"steps/online/nnet2/extract_ivectors_online.sh: combining iVectors across jobs\n",
"steps/online/nnet2/extract_ivectors_online.sh: done extracting (online) iVectors to exp/ivectors_test using the extractor in exp/extractor.\n",
"steps/nnet3/decode.sh --nj 4 --acwt 1.0 --post-decode-acwt 10.0 --online-ivector-dir exp/ivectors_test exp/tdnn/graph_adapt data_test/test_small exp/tdnn/decode_test_adapt\n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: One of the directories do not contain iVector ID.\n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: That means it's you who's reponsible for keeping \n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: the directories compatible\n",
"steps/nnet3/decode.sh: feature type is raw\n",
"steps/diagnostic/analyze_lats.sh --cmd run.pl --iter final exp/tdnn/graph_adapt exp/tdnn/decode_test_adapt\n",
"steps/diagnostic/analyze_lats.sh: see stats in exp/tdnn/decode_test_adapt/log/analyze_alignments.log\n",
"Overall, lattice depth (10,50,90-percentile)=(1,1,4) and mean=2.4\n",
"steps/diagnostic/analyze_lats.sh: see stats in exp/tdnn/decode_test_adapt/log/analyze_lattice_depth_stats.log\n",
"score best paths\n",
"local/score.sh --cmd run.pl data_test/test_small exp/tdnn/graph_adapt exp/tdnn/decode_test_adapt\n",
"local/score.sh: scoring with word insertion penalty=0.0,0.5,1.0\n",
"score confidence and timing with sclite\n",
"Decoding done.\n",
"steps/nnet3/decode.sh --nj 4 --acwt 1.0 --post-decode-acwt 10.0 --online-ivector-dir exp/ivectors_test exp/tdnn/graph data_test/test_small exp/tdnn/decode_test\n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: One of the directories do not contain iVector ID.\n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: That means it's you who's reponsible for keeping \n",
"steps/nnet2/check_ivectors_compatible.sh: WARNING: the directories compatible\n",
"steps/nnet3/decode.sh: feature type is raw\n",
"steps/diagnostic/analyze_lats.sh --cmd run.pl --iter final exp/tdnn/graph exp/tdnn/decode_test\n",
"steps/diagnostic/analyze_lats.sh: see stats in exp/tdnn/decode_test/log/analyze_alignments.log\n",
"Overall, lattice depth (10,50,90-percentile)=(1,5,23) and mean=10.4\n",
"steps/diagnostic/analyze_lats.sh: see stats in exp/tdnn/decode_test/log/analyze_lattice_depth_stats.log\n",
"score best paths\n",
"local/score.sh --cmd run.pl data_test/test_small exp/tdnn/graph exp/tdnn/decode_test\n",
"local/score.sh: scoring with word insertion penalty=0.0,0.5,1.0\n",
"score confidence and timing with sclite\n",
"Decoding done.\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"!bash RESULTS"
],
"metadata": {
"id": "ABtcNyUDX4S8",
"outputId": "d5e50be7-3293-4a59-94b8-9bfa46736481",
"colab": {
"base_uri": "https://localhost:8080/"
}
},
"execution_count": 11,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"%WER 11.77 [ 107 / 909, 13 ins, 7 del, 87 sub ] exp/tdnn/decode_test/wer_7_1.0\n",
"%WER 0.22 [ 2 / 909, 0 ins, 1 del, 1 sub ] exp/tdnn/decode_test_adapt/wer_10_1.0\n"
]
}
]
}
]
}
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+5 -5
View File
@@ -1,17 +1,17 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import sys
import json
from vosk import Model, KaldiRecognizer, SetLogLevel
SetLogLevel(0)
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
model = Model(lang="en-us")
rec = KaldiRecognizer(model, wf.getframerate())
+3 -3
View File
@@ -1,11 +1,11 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer
import sys
import json
from vosk import Model, KaldiRecognizer
model = Model(lang="en-us")
rec = KaldiRecognizer(model, 8000)
res = json.loads(rec.FinalResult())
print (res)
print(res)
+18 -18
View File
@@ -1,29 +1,29 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import subprocess
import sys
from vosk import Model, KaldiRecognizer, SetLogLevel
SAMPLE_RATE = 16000
SetLogLevel(0)
sample_rate=16000
model = Model(lang="en-us")
rec = KaldiRecognizer(model, sample_rate)
rec = KaldiRecognizer(model, SAMPLE_RATE)
process = subprocess.Popen(['ffmpeg', '-loglevel', 'quiet', '-i',
with subprocess.Popen(["ffmpeg", "-loglevel", "quiet", "-i",
sys.argv[1],
'-ar', str(sample_rate) , '-ac', '1', '-f', 's16le', '-'],
stdout=subprocess.PIPE)
"-ar", str(SAMPLE_RATE) , "-ac", "1", "-f", "s16le", "-"],
stdout=subprocess.PIPE) as process:
while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print(rec.PartialResult())
while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print(rec.PartialResult())
print(rec.FinalResult())
print(rec.FinalResult())
+22 -20
View File
@@ -1,26 +1,25 @@
#!/usr/bin/env python3
import sys
import os
import wave
from time import sleep
import json
from timeit import default_timer as timer
from vosk import BatchModel, BatchRecognizer, GpuInit
from timeit import default_timer as timer
TOT_SAMPLES = 0
GpuInit()
model = BatchModel()
model = BatchModel("model")
with open(sys.argv[1]) as fn:
fnames = fn.readlines()
fds = [open(x.strip(), "rb") for x in fnames]
uids = [fname.strip().split("/")[-1][:-4] for fname in fnames]
recs = [BatchRecognizer(model, 16000) for x in fnames]
results = [""] * len(fnames)
fnames = open(sys.argv[1]).readlines()
fds = [open(x.strip(), "rb") for x in fnames]
uids = [fname.strip().split('/')[-1][:-4] for fname in fnames]
recs = [BatchRecognizer(model, 16000) for x in fnames]
results = [""] * len(fnames)
ended = set()
tot_samples = 0
start_time = timer()
@@ -36,24 +35,27 @@ while True:
ended.add(i)
continue
recs[i].AcceptWaveform(data)
tot_samples += len(data)
TOT_SAMPLES += len(data)
# Wait for results from CUDA
model.Wait()
# Retrieve and add results
for i, fd in enumerate(fds):
res = recs[i].Result()
if len(res) != 0:
results[i] = results[i] + " " + json.loads(res)['text']
res = recs[i].Result()
if len(res) != 0:
results[i] = results[i] + " " + json.loads(res)["text"]
if len(ended) == len(fds):
break
end_time = timer()
for i in range(len(results)):
print (uids[i], results[i].strip())
for i, res in enumerate(results):
print(uids[i], res.strip())
print ("Processed %.3f seconds of audio in %.3f seconds (%.3f xRT)" % (tot_samples / 16000.0 / 2, end_time - start_time,
(tot_samples / 16000.0 / 2 / (end_time - start_time))), file=sys.stderr)
print("Processed %.3f seconds of audio in %.3f seconds (%.3f xRT)"
% (TOT_SAMPLES / 16000.0 / 2,
end_time - start_time,
(TOT_SAMPLES / 16000.0 / 2 / (end_time - start_time))),
file=sys.stderr)
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
import json
import gradio as gr
from vosk import KaldiRecognizer, Model
model = Model(lang="en-us")
def transcribe(data, state):
sample_rate, audio_data = data
audio_data = (audio_data >> 16).astype("int16").tobytes()
if state is None:
rec = KaldiRecognizer(model, sample_rate)
result = []
else:
rec, result = state
if rec.AcceptWaveform(audio_data):
text_result = json.loads(rec.Result())["text"]
if text_result != "":
result.append(text_result)
partial_result = ""
else:
partial_result = json.loads(rec.PartialResult())["partial"] + " "
return "\n".join(result) + "\n" + partial_result, (rec, result)
gr.Interface(
fn=transcribe,
inputs=[
gr.Audio(source="microphone", type="numpy", streaming=True),
"state"
],
outputs=[
"textbox",
"state"
],
live=True).launch(share=True)
+39 -30
View File
@@ -1,11 +1,15 @@
#!/usr/bin/env python3
# prerequisites: as described in https://alphacephei.com/vosk/install and also python module `sounddevice` (simply run command `pip install sounddevice`)
# Example usage using Dutch (nl) recognition model: `python test_microphone.py -m nl`
# For more help run: `python test_microphone.py -h`
import argparse
import os
import queue
import sounddevice as sd
import vosk
import sys
import sounddevice as sd
from vosk import Model, KaldiRecognizer
q = queue.Queue()
@@ -24,8 +28,8 @@ def callback(indata, frames, time, status):
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument(
'-l', '--list-devices', action='store_true',
help='show list of audio devices and exit')
"-l", "--list-devices", action="store_true",
help="show list of audio devices and exit")
args, remaining = parser.parse_known_args()
if args.list_devices:
print(sd.query_devices())
@@ -35,46 +39,51 @@ parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
parents=[parser])
parser.add_argument(
'-f', '--filename', type=str, metavar='FILENAME',
help='audio file to store recording to')
"-f", "--filename", type=str, metavar="FILENAME",
help="audio file to store recording to")
parser.add_argument(
'-d', '--device', type=int_or_str,
help='input device (numeric ID or substring)')
"-d", "--device", type=int_or_str,
help="input device (numeric ID or substring)")
parser.add_argument(
'-r', '--samplerate', type=int, help='sampling rate')
"-r", "--samplerate", type=int, help="sampling rate")
parser.add_argument(
"-m", "--model", type=str, help="language model; e.g. en-us, fr, nl; default is en-us")
args = parser.parse_args(remaining)
try:
if args.samplerate is None:
device_info = sd.query_devices(args.device, 'input')
device_info = sd.query_devices(args.device, "input")
# soundfile expects an int, sounddevice provides a float:
args.samplerate = int(device_info['default_samplerate'])
model = vosk.Model(lang="en-us")
args.samplerate = int(device_info["default_samplerate"])
if args.model is None:
model = Model(lang="en-us")
else:
model = Model(lang=args.model)
if args.filename:
dump_fn = open(args.filename, "wb")
else:
dump_fn = None
with sd.RawInputStream(samplerate=args.samplerate, blocksize = 8000, device=args.device, dtype='int16',
channels=1, callback=callback):
print('#' * 80)
print('Press Ctrl+C to stop the recording')
print('#' * 80)
with sd.RawInputStream(samplerate=args.samplerate, blocksize = 8000, device=args.device,
dtype="int16", channels=1, callback=callback):
print("#" * 80)
print("Press Ctrl+C to stop the recording")
print("#" * 80)
rec = vosk.KaldiRecognizer(model, args.samplerate)
while True:
data = q.get()
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print(rec.PartialResult())
if dump_fn is not None:
dump_fn.write(data)
rec = KaldiRecognizer(model, args.samplerate)
while True:
data = q.get()
if rec.AcceptWaveform(data):
print(rec.Result())
else:
print(rec.PartialResult())
if dump_fn is not None:
dump_fn.write(data)
except KeyboardInterrupt:
print('\nDone')
print("\nDone")
parser.exit(0)
except Exception as e:
parser.exit(type(e).__name__ + ': ' + str(e))
parser.exit(type(e).__name__ + ": " + str(e))
+5 -5
View File
@@ -1,16 +1,16 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import sys
from vosk import Model, KaldiRecognizer, SetLogLevel
SetLogLevel(0)
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
model = Model(lang="en-us")
rec = KaldiRecognizer(model, wf.getframerate())
+8 -8
View File
@@ -1,17 +1,17 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import sys
import json
from vosk import Model, KaldiRecognizer, SetLogLevel
SetLogLevel(0)
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
model = Model(lang="en-us")
rec = KaldiRecognizer(model, wf.getframerate())
@@ -22,12 +22,12 @@ while True:
break
if rec.AcceptWaveform(data):
print(rec.Result())
break
sys.exit(1)
else:
jres = json.loads(rec.PartialResult())
print(jres)
if jres['partial'] == "one zero zero zero":
if jres["partial"] == "one zero zero zero":
print("We can reset recognizer here and start over")
rec.Reset();
rec.Reset()
+5 -5
View File
@@ -1,17 +1,17 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import sys
from vosk import Model, KaldiRecognizer, SetLogLevel
# You can set log level to -1 to disable debug messages
SetLogLevel(0)
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
model = Model(lang="en-us")
+44 -21
View File
@@ -1,33 +1,54 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SpkModel
import os
import sys
import wave
import json
import os
import numpy as np
spk_model_path = "model-spk"
from vosk import Model, KaldiRecognizer, SpkModel
if not os.path.exists(spk_model_path):
print ("Please download the speaker model from https://alphacephei.com/vosk/models and unpack as {} in the current folder.".format(spk_model_path))
exit (1)
SPK_MODEL_PATH = "model-spk"
if not os.path.exists(SPK_MODEL_PATH):
print("Please download the speaker model from "
"https://alphacephei.com/vosk/models and unpack as {SPK_MODEL_PATH} "
"in the current folder.")
sys.exit(1)
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
# Large vocabulary free form recognition
model = Model(lang="en-us")
spk_model = SpkModel(spk_model_path)
spk_model = SpkModel(SPK_MODEL_PATH)
#rec = KaldiRecognizer(model, wf.getframerate(), spk_model)
rec = KaldiRecognizer(model, wf.getframerate())
rec.SetSpkModel(spk_model)
# We compare speakers with cosine distance. We can keep one or several fingerprints for the speaker in a database
# We compare speakers with cosine distance.
# We can keep one or several fingerprints for the speaker in a database
# to distingusih among users.
spk_sig = [-1.110417,0.09703002,1.35658,0.7798632,-0.305457,-0.339204,0.6186931,-0.4521213,0.3982236,-0.004530723,0.7651616,0.6500852,-0.6664245,0.1361499,0.1358056,-0.2887807,-0.1280468,-0.8208137,-1.620276,-0.4628615,0.7870904,-0.105754,0.9739769,-0.3258137,-0.7322628,-0.6212429,-0.5531687,-0.7796484,0.7035915,1.056094,-0.4941756,-0.6521456,-0.2238328,-0.003737517,0.2165709,1.200186,-0.7737719,0.492015,1.16058,0.6135428,-0.7183084,0.3153541,0.3458071,-1.418189,-0.9624157,0.4168292,-1.627305,0.2742135,-0.6166027,0.1962581,-0.6406527,0.4372789,-0.4296024,0.4898657,-0.9531326,-0.2945702,0.7879696,-1.517101,-0.9344181,-0.5049928,-0.005040941,-0.4637912,0.8223695,-1.079849,0.8871287,-0.9732434,-0.5548235,1.879138,-1.452064,-0.1975368,1.55047,0.5941782,-0.52897,1.368219,0.6782904,1.202505,-0.9256122,-0.9718158,-0.9570228,-0.5563112,-1.19049,-1.167985,2.606804,-2.261825,0.01340385,0.2526799,-1.125458,-1.575991,-0.363153,0.3270262,1.485984,-1.769565,1.541829,0.7293826,0.1743717,-0.4759418,1.523451,-2.487134,-1.824067,-0.626367,0.7448186,-1.425648,0.3524166,-0.9903384,3.339342,0.4563958,-0.2876643,1.521635,0.9508078,-0.1398541,0.3867955,-0.7550205,0.6568405,0.09419366,-1.583935,1.306094,-0.3501927,0.1794427,-0.3768163,0.9683866,-0.2442541,-1.696921,-1.8056,-0.6803037,-1.842043,0.3069353,0.9070363,-0.486526]
spk_sig = [-1.110417,0.09703002,1.35658,0.7798632,-0.305457,-0.339204,0.6186931,
-0.4521213,0.3982236,-0.004530723,0.7651616,0.6500852,-0.6664245,0.1361499,
0.1358056,-0.2887807,-0.1280468,-0.8208137,-1.620276,-0.4628615,0.7870904,
-0.105754,0.9739769,-0.3258137,-0.7322628,-0.6212429,-0.5531687,-0.7796484,
0.7035915,1.056094,-0.4941756,-0.6521456,-0.2238328,-0.003737517,0.2165709,
1.200186,-0.7737719,0.492015,1.16058,0.6135428,-0.7183084,0.3153541,0.3458071,
-1.418189,-0.9624157,0.4168292,-1.627305,0.2742135,-0.6166027,0.1962581,
-0.6406527,0.4372789,-0.4296024,0.4898657,-0.9531326,-0.2945702,0.7879696,
-1.517101,-0.9344181,-0.5049928,-0.005040941,-0.4637912,0.8223695,-1.079849,
0.8871287,-0.9732434,-0.5548235,1.879138,-1.452064,-0.1975368,1.55047,
0.5941782,-0.52897,1.368219,0.6782904,1.202505,-0.9256122,-0.9718158,
-0.9570228,-0.5563112,-1.19049,-1.167985,2.606804,-2.261825,0.01340385,
0.2526799,-1.125458,-1.575991,-0.363153,0.3270262,1.485984,-1.769565,
1.541829,0.7293826,0.1743717,-0.4759418,1.523451,-2.487134,-1.824067,
-0.626367,0.7448186,-1.425648,0.3524166,-0.9903384,3.339342,0.4563958,
-0.2876643,1.521635,0.9508078,-0.1398541,0.3867955,-0.7550205,0.6568405,
0.09419366,-1.583935,1.306094,-0.3501927,0.1794427,-0.3768163,0.9683866,
-0.2442541,-1.696921,-1.8056,-0.6803037,-1.842043,0.3069353,0.9070363,-0.486526]
def cosine_dist(x, y):
nx = np.array(x)
@@ -40,16 +61,18 @@ while True:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
print ("Text:", res['text'])
if 'spk' in res:
print ("X-vector:", res['spk'])
print ("Speaker distance:", cosine_dist(spk_sig, res['spk']), "based on", res['spk_frames'], "frames")
print("Text:", res["text"])
if "spk" in res:
print("X-vector:", res["spk"])
print("Speaker distance:", cosine_dist(spk_sig, res["spk"]),
"based on", res["spk_frames"], "frames")
print ("Note that second distance is not very reliable because utterance is too short. Utterances longer than 4 seconds give better xvector")
print("Note that second distance is not very reliable because utterance is too short. "
"Utterances longer than 4 seconds give better xvector")
res = json.loads(rec.FinalResult())
print ("Text:", res['text'])
if 'spk' in res:
print ("X-vector:", res['spk'])
print ("Speaker distance:", cosine_dist(spk_sig, res['spk']), "based on", res['spk_frames'], "frames")
print("Text:", res["text"])
if "spk" in res:
print("X-vector:", res["spk"])
print("Speaker distance:", cosine_dist(spk_sig, res["spk"]),
"based on", res["spk_frames"], "frames")
+10 -41
View File
@@ -1,52 +1,21 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
import sys
import os
import wave
import subprocess
import srt
import json
import datetime
import sys
from vosk import Model, KaldiRecognizer, SetLogLevel
SAMPLE_RATE = 16000
SetLogLevel(-1)
sample_rate=16000
model = Model(lang="en-us")
rec = KaldiRecognizer(model, sample_rate)
rec = KaldiRecognizer(model, SAMPLE_RATE)
rec.SetWords(True)
process = subprocess.Popen(['ffmpeg', '-loglevel', 'quiet', '-i',
with subprocess.Popen(["ffmpeg", "-loglevel", "quiet", "-i",
sys.argv[1],
'-ar', str(sample_rate) , '-ac', '1', '-f', 's16le', '-'],
stdout=subprocess.PIPE)
"-ar", str(SAMPLE_RATE) , "-ac", "1", "-f", "s16le", "-"],
stdout=subprocess.PIPE).stdout as stream:
WORDS_PER_LINE = 7
def transcribe():
results = []
subs = []
while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
results.append(rec.Result())
results.append(rec.FinalResult())
for i, res in enumerate(results):
jres = json.loads(res)
if not 'result' in jres:
continue
words = jres['result']
for j in range(0, len(words), WORDS_PER_LINE):
line = words[j : j + WORDS_PER_LINE]
s = srt.Subtitle(index=len(subs),
content=" ".join([l['word'] for l in line]),
start=datetime.timedelta(seconds=line[0]['start']),
end=datetime.timedelta(seconds=line[-1]['end']))
subs.append(s)
return subs
print (srt.compose(transcribe()))
print(rec.SrtResult(stream))
+13 -13
View File
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer
import sys
import json
import os
from vosk import Model, KaldiRecognizer
model = Model(lang="en-us")
@@ -13,16 +13,16 @@ rec = KaldiRecognizer(model, 16000)
# You can also specify the possible word list
#rec = KaldiRecognizer(model, 16000, "zero oh one two three four five six seven eight nine")
wf = open(sys.argv[1], "rb")
wf.read(44) # skip header
with open(sys.argv[1], "rb") as wf:
wf.read(44) # skip header
while True:
data = wf.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
print (res['text'])
while True:
data = wf.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
res = json.loads(rec.Result())
print(res["text"])
res = json.loads(rec.FinalResult())
print (res['text'])
res = json.loads(rec.FinalResult())
print(res["text"])
+41 -41
View File
@@ -1,67 +1,67 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer, SetLogLevel
from webvtt import WebVTT, Caption
import sys
import os
import subprocess
import json
import textwrap
SetLogLevel(-1)
sample_rate = 16000
model = Model(lang="en-us")
rec = KaldiRecognizer(model, sample_rate)
rec.SetWords(True)
from webvtt import WebVTT, Caption
from vosk import Model, KaldiRecognizer, SetLogLevel
SAMPLE_RATE = 16000
WORDS_PER_LINE = 7
SetLogLevel(-1)
def timeString(seconds):
model = Model(lang="en-us")
rec = KaldiRecognizer(model, SAMPLE_RATE)
rec.SetWords(True)
def timestring(seconds):
minutes = seconds / 60
seconds = seconds % 60
hours = int(minutes / 60)
minutes = int(minutes % 60)
return '%i:%02i:%06.3f' % (hours, minutes, seconds)
return "%i:%02i:%06.3f" % (hours, minutes, seconds)
def transcribe():
command = ['ffmpeg', '-nostdin', '-loglevel', 'quiet', '-i', sys.argv[1],
'-ar', str(sample_rate), '-ac', '1', '-f', 's16le', '-']
process = subprocess.Popen(command, stdout=subprocess.PIPE)
command = ["ffmpeg", "-nostdin", "-loglevel", "quiet", "-i", sys.argv[1],
"-ar", str(SAMPLE_RATE), "-ac", "1", "-f", "s16le", "-"]
with subprocess.Popen(command, stdout=subprocess.PIPE) as process:
results = []
while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
results.append(rec.Result())
results.append(rec.FinalResult())
results = []
while True:
data = process.stdout.read(4000)
if len(data) == 0:
break
if rec.AcceptWaveform(data):
results.append(rec.Result())
results.append(rec.FinalResult())
vtt = WebVTT()
for i, res in enumerate(results):
words = json.loads(res).get('result')
if not words:
continue
vtt = WebVTT()
for _, res in enumerate(results):
words = json.loads(res).get("result")
if not words:
continue
start = timeString(words[0]['start'])
end = timeString(words[-1]['end'])
content = ' '.join([w['word'] for w in words])
start = timestring(words[0]["start"])
end = timestring(words[-1]["end"])
content = " ".join([w["word"] for w in words])
caption = Caption(start, end, textwrap.fill(content))
vtt.captions.append(caption)
caption = Caption(start, end, textwrap.fill(content))
vtt.captions.append(caption)
# save or return webvtt
if len(sys.argv) > 2:
vtt.save(sys.argv[2])
else:
print(vtt.content)
# save or return webvtt
if len(sys.argv) > 2:
vtt.save(sys.argv[2])
else:
print(vtt.content)
if __name__ == '__main__':
if not (1 < len(sys.argv) < 4):
print(f'Usage: {sys.argv[0]} audiofile [output file]')
exit(1)
if __name__ == "__main__":
if not 1 < len(sys.argv) < 4:
print("Usage: {} audiofile [output file]".format(sys.argv[0]))
sys.exit(1)
transcribe()
+11 -7
View File
@@ -1,19 +1,22 @@
#!/usr/bin/env python3
from vosk import Model, KaldiRecognizer
import sys
import os
import wave
import sys
from vosk import Model, KaldiRecognizer
wf = wave.open(sys.argv[1], "rb")
if wf.getnchannels() != 1 or wf.getsampwidth() != 2 or wf.getcomptype() != "NONE":
print ("Audio file must be WAV format mono PCM.")
exit (1)
print("Audio file must be WAV format mono PCM.")
sys.exit(1)
model = Model(lang="en-us")
# You can also specify the possible word or phrase list as JSON list, the order doesn't have to be strict
rec = KaldiRecognizer(model, wf.getframerate(), '["oh one two three four five six seven eight nine zero", "[unk]"]')
# You can also specify the possible word or phrase list as JSON list,
# the order doesn't have to be strict
rec = KaldiRecognizer(model,
wf.getframerate(),
'["oh one two three", "four five six", "seven eight nine zero", "[unk]"]')
while True:
data = wf.readframes(4000)
@@ -21,6 +24,7 @@ while True:
break
if rec.AcceptWaveform(data):
print(rec.Result())
rec.SetGrammar('["one zero one two three oh", "four five six", "seven eight nine zero", "[unk]"]')
else:
print(rec.PartialResult())
+12 -11
View File
@@ -1,14 +1,15 @@
import os
import sys
import setuptools
import shutil
import glob
import platform
# Figure out environment for cross-compile
vosk_source = os.getenv("VOSK_SOURCE", os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
system = os.environ.get('VOSK_PLATFORM', platform.system())
vosk_source = os.getenv("VOSK_SOURCE", os.path.abspath(os.path.join(os.path.dirname(__file__),
"..")))
system = os.environ.get('VOSK_SYSTEM', platform.system())
architecture = os.environ.get('VOSK_ARCHITECTURE', platform.architecture()[0])
machine = os.environ.get('VOSK_MACHINE', platform.machine())
# Copy precompmilled libraries
for lib in glob.glob(os.path.join(vosk_source, "src/lib*.*")):
@@ -30,21 +31,21 @@ else:
oses = 'win32'
elif system == 'Windows' and architecture == '64bit':
oses = 'win_amd64'
elif system == 'Linux' and architecture == '64bit':
oses = 'linux_x86_64'
elif system == 'Linux' and machine == 'aarch64' and architecture == '64bit':
oses = 'manylinux2014_aarch64'
elif system == 'Linux':
oses = 'linux_' + architecture
oses = 'linux_' + machine
else:
raise TypeError("Unknown build environment")
return 'py3', abi, oses
cmdclass = {'bdist_wheel': bdist_wheel_tag_name}
with open("README.md", "r") as fh:
long_description = fh.read()
with open("README.md", "rb") as fh:
long_description = fh.read().decode("utf-8")
setuptools.setup(
name="vosk",
version="0.3.41",
version="0.3.45",
author="Alpha Cephei Inc",
author_email="contact@alphacephei.com",
description="Offline open source speech recognition API based on Kaldi and Vosk",
@@ -68,7 +69,7 @@ setuptools.setup(
cmdclass=cmdclass,
python_requires='>=3',
zip_safe=False, # Since we load so file from the filesystem, we can not run from zip file
setup_requires=['cffi>=1.0', 'requests', 'tqdm'],
install_requires=['cffi>=1.0', 'requests', 'tqdm'],
setup_requires=['cffi>=1.0', 'requests', 'tqdm', 'srt', 'websockets'],
install_requires=['cffi>=1.0', 'requests', 'tqdm', 'srt', 'websockets'],
cffi_modules=['vosk_builder.py:ffibuilder'],
)
+9 -10
View File
@@ -1,14 +1,13 @@
#!/usr/bin/env python3
import wave
import json
import sys
from multiprocessing.dummy import Pool
from vosk import Model, KaldiRecognizer
import sys
import os
import wave
import json
model = Model("model")
model = Model("en-us")
def recognize(line):
uid, fn = line.split()
@@ -22,14 +21,14 @@ def recognize(line):
break
if rec.AcceptWaveform(data):
jres = json.loads(rec.Result())
text = text + " " + jres['text']
text = text + " " + jres["text"]
jres = json.loads(rec.FinalResult())
text = text + " " + jres['text']
return (uid + text)
text = text + " " + jres["text"]
return uid + text
def main():
p = Pool(8)
texts = p.map(recognize, open(sys.argv[1]).readlines())
texts = p.map(recognize, open(sys.argv[1], encoding="uft-8").readlines())
print ("\n".join(texts))
main()
+87 -47
View File
@@ -1,5 +1,8 @@
import os
import sys
import srt
import datetime
import json
import requests
from urllib.request import urlretrieve
@@ -10,21 +13,22 @@ from .vosk_cffi import ffi as _ffi
from tqdm import tqdm
# Remote location of the models and local folders
MODEL_PRE_URL = 'https://alphacephei.com/vosk/models/'
MODEL_LIST_URL = MODEL_PRE_URL + 'model-list.json'
MODEL_DIRS = [os.getenv('VOSK_MODEL_PATH'), Path('/usr/share/vosk'), Path.home() / 'AppData/Local/vosk', Path.home() / '.cache/vosk']
MODEL_PRE_URL = "https://alphacephei.com/vosk/models/"
MODEL_LIST_URL = MODEL_PRE_URL + "model-list.json"
MODEL_DIRS = [os.getenv("VOSK_MODEL_PATH"), Path("/usr/share/vosk"),
Path.home() / "AppData/Local/vosk", Path.home() / ".cache/vosk"]
def open_dll():
dlldir = os.path.abspath(os.path.dirname(__file__))
if sys.platform == 'win32':
if sys.platform == "win32":
# We want to load dependencies too
os.environ["PATH"] = dlldir + os.pathsep + os.environ['PATH']
if hasattr(os, 'add_dll_directory'):
os.environ["PATH"] = dlldir + os.pathsep + os.environ["PATH"]
if hasattr(os, "add_dll_directory"):
os.add_dll_directory(dlldir)
return _ffi.dlopen(os.path.join(dlldir, "libvosk.dll"))
elif sys.platform == 'linux':
elif sys.platform == "linux":
return _ffi.dlopen(os.path.join(dlldir, "libvosk.so"))
elif sys.platform == 'darwin':
elif sys.platform == "darwin":
return _ffi.dlopen(os.path.join(dlldir, "libvosk.dyld"))
else:
raise TypeError("Unsupported platform")
@@ -32,23 +36,23 @@ def open_dll():
_c = open_dll()
def list_models():
response = requests.get(MODEL_LIST_URL)
response = requests.get(MODEL_LIST_URL, timeout=10)
for model in response.json():
print(model['name'])
print(model["name"])
def list_languages():
response = requests.get(MODEL_LIST_URL)
languages = set([m['lang'] for m in response.json()])
response = requests.get(MODEL_LIST_URL, timeout=10)
languages = {m["lang"] for m in response.json()}
for lang in languages:
print (lang)
class Model(object):
class Model:
def __init__(self, model_path=None, model_name=None, lang=None):
if model_path != None:
self._handle = _c.vosk_model_new(model_path.encode('utf-8'))
if model_path is not None:
self._handle = _c.vosk_model_new(model_path.encode("utf-8"))
else:
model_path = self.get_model_path(model_name, lang)
self._handle = _c.vosk_model_new(model_path.encode('utf-8'))
self._handle = _c.vosk_model_new(model_path.encode("utf-8"))
if self._handle == _ffi.NULL:
raise Exception("Failed to create a model")
@@ -56,7 +60,7 @@ class Model(object):
_c.vosk_model_free(self._handle)
def vosk_model_find_word(self, word):
return _c.vosk_model_find_word(self._handle, word.encode('utf-8'))
return _c.vosk_model_find_word(self._handle, word.encode("utf-8"))
def get_model_path(self, model_name, lang):
if model_name is None:
@@ -73,10 +77,11 @@ class Model(object):
model_file = [model for model in model_file_list if model == model_name]
if model_file != []:
return Path(directory, model_file[0])
response = requests.get(MODEL_LIST_URL)
result_model = [model['name'] for model in response.json() if model['name'] == model_name]
response = requests.get(MODEL_LIST_URL, timeout=10)
result_model = [model["name"] for model in response.json() if model["name"] == model_name]
if result_model == []:
raise Exception("model name %s does not exist" % (model_name))
print("model name %s does not exist" % (model_name))
sys.exit(1)
else:
self.download_model(Path(directory, result_model[0]))
return Path(directory, result_model[0])
@@ -86,29 +91,33 @@ class Model(object):
if directory is None or not Path(directory).exists():
continue
model_file_list = os.listdir(directory)
model_file = [model for model in model_file_list if match(f"vosk-model(-small)?-{lang}", model)]
model_file = [model for model in model_file_list if
match(r"vosk-model(-small)?-{}".format(lang), model)]
if model_file != []:
return Path(directory, model_file[0])
response = requests.get(MODEL_LIST_URL)
result_model = [model['name'] for model in response.json() if model['lang'] == lang and model['type'] == 'small' and model['obsolete'] == 'false']
response = requests.get(MODEL_LIST_URL, timeout=10)
result_model = [model["name"] for model in response.json() if
model["lang"] == lang and model["type"] == "small" and model["obsolete"] == "false"]
if result_model == []:
raise Exception("lang %s does not exist" % (lang))
print("lang %s does not exist" % (lang))
sys.exit(1)
else:
self.download_model(Path(directory, result_model[0]))
return Path(directory, result_model[0])
def download_model(self, model_name):
if not MODEL_DIRS[3].exists():
MODEL_DIRS[3].mkdir()
with tqdm(unit='B', unit_scale=True, unit_divisor=1024, miniters=1,
desc=(MODEL_PRE_URL + str(model_name.name) + '.zip').split('/')[-1]) as t:
if not (model_name.parent).exists():
(model_name.parent).mkdir(parents=True)
with tqdm(unit="B", unit_scale=True, unit_divisor=1024, miniters=1,
desc=(MODEL_PRE_URL + str(model_name.name) + ".zip").rsplit("/",
maxsplit=1)[-1]) as t:
reporthook = self.download_progress_hook(t)
urlretrieve(MODEL_PRE_URL + str(model_name.name) + '.zip', str(model_name) + '.zip',
reporthook=reporthook, data=None)
urlretrieve(MODEL_PRE_URL + str(model_name.name) + ".zip",
str(model_name) + ".zip", reporthook=reporthook, data=None)
t.total = t.n
with ZipFile(str(model_name) + '.zip', 'r') as model_ref:
with ZipFile(str(model_name) + ".zip", "r") as model_ref:
model_ref.extractall(model_name.parent)
Path(str(model_name) + '.zip').unlink()
Path(str(model_name) + ".zip").unlink()
def download_progress_hook(self, t):
last_b = [0]
@@ -120,10 +129,10 @@ class Model(object):
return displayed
return update_to
class SpkModel(object):
class SpkModel:
def __init__(self, model_path):
self._handle = _c.vosk_spk_model_new(model_path.encode('utf-8'))
self._handle = _c.vosk_spk_model_new(model_path.encode("utf-8"))
if self._handle == _ffi.NULL:
raise Exception("Failed to create a speaker model")
@@ -131,15 +140,17 @@ class SpkModel(object):
def __del__(self):
_c.vosk_spk_model_free(self._handle)
class KaldiRecognizer(object):
class KaldiRecognizer:
def __init__(self, *args):
if len(args) == 2:
self._handle = _c.vosk_recognizer_new(args[0]._handle, args[1])
elif len(args) == 3 and type(args[2]) is SpkModel:
self._handle = _c.vosk_recognizer_new_spk(args[0]._handle, args[1], args[2]._handle)
elif len(args) == 3 and type(args[2]) is str:
self._handle = _c.vosk_recognizer_new_grm(args[0]._handle, args[1], args[2].encode('utf-8'))
elif len(args) == 3 and isinstance(args[2], SpkModel):
self._handle = _c.vosk_recognizer_new_spk(args[0]._handle,
args[1], args[2]._handle)
elif len(args) == 3 and isinstance(args[2], str):
self._handle = _c.vosk_recognizer_new_grm(args[0]._handle,
args[1], args[2].encode("utf-8"))
else:
raise TypeError("Unknown arguments")
@@ -164,6 +175,9 @@ class KaldiRecognizer(object):
def SetSpkModel(self, spk_model):
_c.vosk_recognizer_set_spk_model(self._handle, spk_model._handle)
def SetGrammar(self, grammar):
_c.vosk_recognizer_set_grm(self._handle, grammar.encode("utf-8"))
def AcceptWaveform(self, data):
res = _c.vosk_recognizer_accept_waveform(self._handle, data, len(data))
if res < 0:
@@ -171,17 +185,43 @@ class KaldiRecognizer(object):
return res
def Result(self):
return _ffi.string(_c.vosk_recognizer_result(self._handle)).decode('utf-8')
return _ffi.string(_c.vosk_recognizer_result(self._handle)).decode("utf-8")
def PartialResult(self):
return _ffi.string(_c.vosk_recognizer_partial_result(self._handle)).decode('utf-8')
return _ffi.string(_c.vosk_recognizer_partial_result(self._handle)).decode("utf-8")
def FinalResult(self):
return _ffi.string(_c.vosk_recognizer_final_result(self._handle)).decode('utf-8')
return _ffi.string(_c.vosk_recognizer_final_result(self._handle)).decode("utf-8")
def Reset(self):
return _c.vosk_recognizer_reset(self._handle)
def SrtResult(self, stream, words_per_line = 7):
results = []
while True:
data = stream.read(4000)
if len(data) == 0:
break
if self.AcceptWaveform(data):
results.append(self.Result())
results.append(self.FinalResult())
subs = []
for res in results:
jres = json.loads(res)
if not "result" in jres:
continue
words = jres["result"]
for j in range(0, len(words), words_per_line):
line = words[j : j + words_per_line]
s = srt.Subtitle(index=len(subs),
content=" ".join([l["word"] for l in line]),
start=datetime.timedelta(seconds=line[0]["start"]),
end=datetime.timedelta(seconds=line[-1]["end"]))
subs.append(s)
return srt.compose(subs)
def SetLogLevel(level):
return _c.vosk_set_log_level(level)
@@ -194,10 +234,10 @@ def GpuInit():
def GpuThreadInit():
_c.vosk_gpu_thread_init()
class BatchModel(object):
class BatchModel:
def __init__(self, *args):
self._handle = _c.vosk_batch_model_new()
def __init__(self, model_path, *args):
self._handle = _c.vosk_batch_model_new(model_path.encode('utf-8'))
if self._handle == _ffi.NULL:
raise Exception("Failed to create a model")
@@ -208,7 +248,7 @@ class BatchModel(object):
def Wait(self):
_c.vosk_batch_model_wait(self._handle)
class BatchRecognizer(object):
class BatchRecognizer:
def __init__(self, *args):
self._handle = _c.vosk_batch_recognizer_new(args[0]._handle, args[1])
@@ -224,7 +264,7 @@ class BatchRecognizer(object):
def Result(self):
ptr = _c.vosk_batch_recognizer_front_result(self._handle)
res = _ffi.string(ptr).decode('utf-8')
res = _ffi.string(ptr).decode("utf-8")
_c.vosk_batch_recognizer_pop(self._handle)
return res
+48 -37
View File
@@ -1,41 +1,49 @@
#!/usr/bin/env python3
import logging
import argparse
import logging
import sys
import os
from pathlib import Path
from vosk import list_models, list_languages
from vosk.transcriber.transcriber import Transcriber
parser = argparse.ArgumentParser(
description = 'Transcribe audio file and save result in selected format')
description = "Transcribe audio file and save result in selected format")
parser.add_argument(
'--model', '-m', type=str,
help='model path')
"--model", "-m", type=str,
help="model path")
parser.add_argument(
'--list-models', default=False, action='store_true',
help='list available models')
"--server", "-s", const="ws://localhost:2700", action="store_const",
help="use server for recognition")
parser.add_argument(
'--list-languages', default=False, action='store_true',
help='list available languages')
"--list-models", default=False, action="store_true",
help="list available models")
parser.add_argument(
'--model-name', '-n', type=str,
help='select model by name')
"--list-languages", default=False, action="store_true",
help="list available languages")
parser.add_argument(
'--lang', '-l', default='en-us', type=str,
help='select model by language')
"--model-name", "-n", type=str,
help="select model by name")
parser.add_argument(
'--input', '-i', type=str,
help='audiofile')
"--lang", "-l", default="en-us", type=str,
help="select model by language")
parser.add_argument(
'--output', '-o', default='', type=str,
help='optional output filename path')
"--input", "-i", type=str,
help="audiofile")
parser.add_argument(
'--output-type', '-t', default='txt', type=str,
help='optional arg output data type')
"--output", "-o", default="", type=str,
help="optional output filename path")
parser.add_argument(
'--log-level', default='INFO',
help='logging level')
"--output-type", "-t", default="txt", type=str,
help="optional arg output data type")
parser.add_argument(
"--tasks", "-ts", default=10, type=int,
help="number of parallel recognition tasks")
parser.add_argument(
"--log-level", default="INFO",
help="logging level")
def main():
@@ -43,36 +51,39 @@ def main():
log_level = args.log_level.upper()
logging.getLogger().setLevel(log_level)
if args.list_models == True:
if args.list_models is True:
list_models()
return
if args.list_languages == True:
if args.list_languages is True:
list_languages()
return
if not args.input:
logging.info('Please specify input file or directory')
exit(1)
logging.info("Please specify input file or directory")
sys.exit(1)
if not Path(args.input).exists():
logging.info('File %s does not exist, please specify an existing file/directory' % (args.input))
exit(1)
if args.output !='' and not Path(args.output).exists():
logging.info('Output %s does not exist, please specify an existing file' % (args.output))
exit(1)
logging.info("File/folder {args.input} does not exist, "\
"please specify an existing file/directory")
sys.exit(1)
transcriber = Transcriber(args)
if Path(args.input).is_dir() and Path(args.output).is_dir():
transcriber.process_dir(args)
return
elif Path(args.input).is_file() and (args.output=='' or Path(args.output).is_file()):
transcriber.process_file(args)
if Path(args.input).is_dir():
task_list = [(Path(args.input, fn),
Path(args.output,
Path(fn).stem).with_suffix("." + args.output_type)) for fn in os.listdir(args.input)]
elif Path(args.input).is_file():
if args.output == "":
task_list = [(Path(args.input), args.output)]
else:
task_list = [(Path(args.input), Path(args.output))]
else:
logging.info('Wrong arguments, input and output must be same type')
exit(1)
logging.info("Wrong arguments")
sys.exit(1)
transcriber.process_task_list(task_list)
if __name__ == "__main__":
main()
+154 -48
View File
@@ -1,89 +1,195 @@
import json
import subprocess
import logging
import asyncio
import websockets
import srt
import datetime
import os
import logging
import shlex
import subprocess
from pathlib import Path
from timeit import default_timer as timer
from vosk import KaldiRecognizer, Model
from queue import Queue
from timeit import default_timer as timer
from multiprocessing.dummy import Pool
CHUNK_SIZE = 4000
SAMPLE_RATE = 16000.0
class Transcriber:
def __init__(self, args):
self.model = Model(model_path=args.model, model_name=args.model_name, lang=args.lang)
self.args = args
self.queue = Queue()
def recognize_stream(self, rec, stream):
tot_samples = 0
result = []
while True:
data = stream.stdout.read(4000)
data = stream.stdout.read(CHUNK_SIZE)
if len(data) == 0:
break
tot_samples += len(data)
if rec.AcceptWaveform(data):
tot_samples += len(data)
result.append(json.loads(rec.Result()))
result.append(json.loads(rec.FinalResult()))
jres = json.loads(rec.Result())
logging.info(jres)
result.append(jres)
else:
jres = json.loads(rec.PartialResult())
if jres["partial"] != "":
logging.info(jres)
jres = json.loads(rec.FinalResult())
result.append(jres)
return result, tot_samples
async def recognize_stream_server(self, proc):
async with websockets.connect(self.args.server) as websocket:
tot_samples = 0
result = []
await websocket.send('{ "config" : { "sample_rate" : %f } }' % (SAMPLE_RATE))
while True:
data = await proc.stdout.read(CHUNK_SIZE)
tot_samples += len(data)
if len(data) == 0:
break
await websocket.send(data)
jres = json.loads(await websocket.recv())
logging.info(jres)
if not "partial" in jres:
result.append(jres)
await websocket.send('{"eof" : 1}')
jres = json.loads(await websocket.recv())
logging.info(jres)
result.append(jres)
return result, tot_samples
def format_result(self, result, words_per_line=7):
final_result = ''
if self.args.output_type == 'srt':
processed_result = ""
if self.args.output_type == "srt":
subs = []
for i, res in enumerate(result):
if not 'result' in res:
for _, res in enumerate(result):
if not "result" in res:
continue
words = res['result']
words = res["result"]
for j in range(0, len(words), words_per_line):
line = words[j : j + words_per_line]
s = srt.Subtitle(index=len(subs),
content = ' '.join([l['word'] for l in line]),
start=datetime.timedelta(seconds=line[0]['start']),
end=datetime.timedelta(seconds=line[-1]['end']))
content = " ".join([l["word"] for l in line]),
start=datetime.timedelta(seconds=line[0]["start"]),
end=datetime.timedelta(seconds=line[-1]["end"]))
subs.append(s)
final_result = srt.compose(subs)
elif self.args.output_type == 'txt':
for part in result:
final_result += part['text'] + ' '
return final_result
processed_result = srt.compose(subs)
elif self.args.output_type == "txt":
for part in result:
if part["text"] != "":
processed_result += part["text"] + "\n"
elif self.args.output_type == "json":
monologues = {"schemaVersion":"2.0", "monologues":[], "text":[]}
for part in result:
if part["text"] != "":
monologue["text"] += part["text"]
for _, res in enumerate(result):
if not "result" in res:
continue
monologue = { "speaker": {"id": "unknown", "name": None}, "start": 0, "end": 0, "terms": []}
monologue["start"] = res["result"][0]["start"]
monologue["end"] = res["result"][-1]["end"]
monologue["terms"] = [{"confidence": t["conf"], "start": t["start"], "end": t["end"], "text": t["word"], "type": "WORD" } for t in res["result"]]
monologues["monologues"].append(monologue)
processed_result = json.dumps(monologues)
return processed_result
def resample_ffmpeg(self, infile):
stream = subprocess.Popen(
['ffmpeg', '-nostdin', '-loglevel', 'quiet', '-i',
infile,
'-ar', '16000','-ac', '1', '-f', 's16le', '-'],
stdout=subprocess.PIPE)
cmd = shlex.split("ffmpeg -nostdin -loglevel quiet "
"-i \'{}\' -ar {} -ac 1 -f s16le -".format(str(infile), SAMPLE_RATE))
stream = subprocess.Popen(cmd, stdout=subprocess.PIPE)
return stream
async def resample_ffmpeg_async(self, infile):
cmd = "ffmpeg -nostdin -loglevel quiet "\
"-i \'{}\' -ar {} -ac 1 -f s16le -".format(str(infile), SAMPLE_RATE)
return await asyncio.create_subprocess_shell(cmd, stdout=subprocess.PIPE)
def process_entry(self, inputdata):
logging.info(f'Recognizing {inputdata[0]}')
async def server_worker(self):
while True:
try:
input_file, output_file = self.queue.get_nowait()
except Exception:
break
rec = KaldiRecognizer(self.model, 16000)
rec.SetWords(True)
logging.info("Recognizing {}".format(input_file))
start_time = timer()
proc = await self.resample_ffmpeg_async(input_file)
result, tot_samples = await self.recognize_stream_server(proc)
stream = self.resample_ffmpeg(inputdata[0])
result, tot_samples = self.recognize_stream(rec, stream)
final_result = self.format_result(result)
processed_result = self.format_result(result)
if output_file != "":
logging.info("File {} processing complete".format(output_file))
with open(output_file, "w", encoding="utf-8") as fh:
fh.write(processed_result)
else:
print(processed_result)
if inputdata[1] != '':
with open(inputdata[1], 'w', encoding='utf-8') as fh:
fh.write(final_result)
else:
print(final_result)
return final_result, tot_samples
await proc.wait()
elapsed = timer() - start_time
logging.info("Execution time: {:.3f} sec; "\
"xRT {:.3f}".format(elapsed, float(elapsed) * (2 * SAMPLE_RATE) / tot_samples))
self.queue.task_done()
def process_directory(self,args):
task_list = [(Path(args.input, fn), Path(args.output, Path(fn).stem).with_suffix('.' + args.output_type)) for fn in os.listdir(args.input)]
with Pool() as pool:
pool.map(self.process_entry, file_list)
def process_file(self, args):
def pool_worker(self, inputdata):
logging.info("Recognizing {}".format(inputdata[0]))
start_time = timer()
final_result, tot_samples = self.process_entry([args.input, args.output])
try:
stream = self.resample_ffmpeg(inputdata[0])
except FileNotFoundError as e:
print(e, "Missing FFMPEG, please install and try again")
return
except Exception as e:
logging.info(e)
return
rec = KaldiRecognizer(self.model, SAMPLE_RATE)
rec.SetWords(True)
result, tot_samples = self.recognize_stream(rec, stream)
processed_result = self.format_result(result)
if inputdata[1] != "":
logging.info("File {} processing complete".format(inputdata[1]))
with open(inputdata[1], "w", encoding="utf-8") as fh:
fh.write(processed_result)
else:
print(processed_result)
elapsed = timer() - start_time
logging.info(f'''Execution time: {elapsed:.3f} sec; xRT: {format(tot_samples / 16000.0 / float(elapsed), '.3f')}''')
logging.info("Execution time: {:.3f} sec; "\
"xRT {:.3f}".format(elapsed, float(elapsed) * (2 * SAMPLE_RATE) / tot_samples))
async def process_task_list_server(self, task_list):
for x in task_list:
self.queue.put(x)
workers = [asyncio.create_task(self.server_worker()) for i in range(self.args.tasks)]
await asyncio.gather(*workers)
def process_task_list_pool(self, task_list):
with Pool() as pool:
pool.map(self.pool_worker, task_list)
def process_task_list(self, task_list):
if self.args.server is None:
self.process_task_list_pool(task_list)
else:
asyncio.run(self.process_task_list_server(task_list))
+5
View File
@@ -0,0 +1,5 @@
class Vosk
def self.hi
puts "Hello world!"
end
end
+12
View File
@@ -0,0 +1,12 @@
Gem::Specification.new do |s|
s.name = "vosk"
s.version = "0.3.45"
s.summary = "Offline speech recognition API"
s.description = "Vosk is an offline open source speech recognition toolkit. It enables speech recognition for 20+ languages and dialects - English, Indian English, German, French, Spanish, Portuguese, Chinese, Russian, Turkish, Vietnamese, Italian, Dutch, Catalan, Arabic, Greek, Farsi, Filipino, Ukrainian, Kazakh, Swedish, Japanese, Esperanto, Hindi, Czech, Polish. More to come."
s.authors = ["Alpha Cephei Inc"]
s.email = "contact@alphacphei.com"
s.files = ["lib/vosk.rb"]
s.homepage =
"https://rubygems.org/gems/vosk"
s.license = "Apache 2.0"
end
+5
View File
@@ -0,0 +1,5 @@
See
https://github.com/Bear-03/vosk-rs
https://crates.io/crates/vosk
+26 -12
View File
@@ -20,21 +20,21 @@ using namespace fst;
using namespace kaldi::nnet3;
using CorrelationID = CudaOnlinePipelineDynamicBatcher::CorrelationID;
BatchModel::BatchModel() {
BatchModel::BatchModel(const char *model_path) : model_path_str_(model_path) {
BatchedThreadedNnet3CudaOnlinePipelineConfig batched_decoder_config;
kaldi::ParseOptions po("something");
batched_decoder_config.Register(&po);
po.ReadConfigFile("model/conf/model.conf");
po.ReadConfigFile(model_path_str_ + "/conf/model.conf");
struct stat buffer;
string nnet3_rxfilename_ = "model/am/final.mdl";
string hclg_fst_rxfilename_ = "model/graph/HCLG.fst";
string word_syms_rxfilename_ = "model/graph/words.txt";
string winfo_rxfilename_ = "model/graph/phones/word_boundary.int";
string std_fst_rxfilename_ = "model/rescore/G.fst";
string carpa_rxfilename_ = "model/rescore/G.carpa";
string nnet3_rxfilename_ = model_path_str_ + "/am/final.mdl";
string hclg_fst_rxfilename_ = model_path_str_ + "/graph/HCLG.fst";
string word_syms_rxfilename_ = model_path_str_ + "/graph/words.txt";
string winfo_rxfilename_ = model_path_str_ + "/graph/phones/word_boundary.int";
string std_fst_rxfilename_ = model_path_str_ + "/rescore/G.fst";
string carpa_rxfilename_ = model_path_str_ + "/rescore/G.carpa";
trans_model_ = new kaldi::TransitionModel();
nnet_ = new kaldi::nnet3::AmNnetSimple();
@@ -72,9 +72,23 @@ BatchModel::BatchModel() {
batched_decoder_config.reset_on_endpoint = true;
batched_decoder_config.use_gpu_feature_extraction = true;
batched_decoder_config.feature_opts.feature_type = "mfcc";
batched_decoder_config.feature_opts.mfcc_config = "model/conf/mfcc.conf";
batched_decoder_config.feature_opts.ivector_extraction_config = "model/conf/ivector.conf";
feature_info_.feature_type = "mfcc";
ReadConfigFromFile(model_path_str_ + "/conf/mfcc.conf", &feature_info_.mfcc_opts);
feature_info_.silence_weighting_config.silence_weight = 1e-3;
feature_info_.silence_weighting_config.silence_phones_str = batched_decoder_config.decoder_opts.endpointing_config.silence_phones;
OnlineIvectorExtractionConfig ivector_extraction_opts;
ivector_extraction_opts.splice_config_rxfilename = model_path_str_ + "/ivector/splice.conf";
ivector_extraction_opts.cmvn_config_rxfilename = model_path_str_ + "/ivector/online_cmvn.conf";
ivector_extraction_opts.lda_mat_rxfilename = model_path_str_ + "/ivector/final.mat";
ivector_extraction_opts.global_cmvn_stats_rxfilename = model_path_str_ + "/ivector/global_cmvn.stats";
ivector_extraction_opts.diag_ubm_rxfilename = model_path_str_ + "/ivector/final.dubm";
ivector_extraction_opts.ivector_extractor_rxfilename = model_path_str_ + "/ivector/final.ie";
ivector_extraction_opts.max_count = 100;
feature_info_.use_ivectors = true;
feature_info_.ivector_extractor_info.Init(ivector_extraction_opts);
batched_decoder_config.decoder_opts.max_active = 7000;
batched_decoder_config.decoder_opts.default_beam = 13.0;
batched_decoder_config.decoder_opts.lattice_beam = 6.0;
@@ -88,7 +102,7 @@ BatchModel::BatchModel() {
batched_decoder_config.compute_opts.frames_per_chunk = std::max(51, (nnet_right_context + 3 - nnet_right_context % 3));
cuda_pipeline_ = new BatchedThreadedNnet3CudaOnlinePipeline
(batched_decoder_config, *hclg_fst_, *nnet_, *trans_model_);
(batched_decoder_config, feature_info_, *hclg_fst_, *nnet_, *trans_model_);
cuda_pipeline_->SetSymbolTable(*word_syms_);
CudaOnlinePipelineDynamicBatcherConfig dynamic_batcher_config;
+4 -1
View File
@@ -42,7 +42,7 @@ class BatchRecognizer;
class BatchModel {
public:
BatchModel();
BatchModel(const char *model_path);
~BatchModel();
uint64_t GetID(BatchRecognizer *recognizer);
@@ -51,6 +51,9 @@ class BatchModel {
private:
friend class BatchRecognizer;
std::string model_path_str_;
OnlineNnet2FeaturePipelineInfo feature_info_;
kaldi::TransitionModel *trans_model_ = nullptr;
kaldi::nnet3::AmNnetSimple *nnet_ = nullptr;
const fst::SymbolTable *word_syms_ = nullptr;
+7 -2
View File
@@ -282,7 +282,10 @@ void Model::ReadDataFiles()
KALDI_LOG << "Loading HCL and G from " << hcl_fst_rxfilename_ << " " << g_fst_rxfilename_;
hcl_fst_ = fst::StdFst::Read(hcl_fst_rxfilename_);
g_fst_ = fst::StdFst::Read(g_fst_rxfilename_);
ReadIntegerVectorSimple(disambig_rxfilename_, &disambig_);
if (!ReadIntegerVectorSimple(disambig_rxfilename_, &disambig_)) {
KALDI_ERR << "Could not read disambig symbol table from file "
<< disambig_rxfilename_;
}
}
if (hclg_fst_ && hclg_fst_->OutputSymbols()) {
@@ -297,7 +300,9 @@ void Model::ReadDataFiles()
<< word_syms_rxfilename_;
word_syms_loaded_ = word_syms_;
}
KALDI_ASSERT(word_syms_);
if (!word_syms_) {
KALDI_ERR << "Word symbol table empty";
}
if (stat(winfo_rxfilename_.c_str(), &buffer) == 0) {
KALDI_LOG << "Loading winfo " << winfo_rxfilename_;
+106 -41
View File
@@ -54,45 +54,7 @@ Recognizer::Recognizer(Model *model, float sample_frequency, char const *grammar
silence_weighting_ = new kaldi::OnlineSilenceWeighting(*model_->trans_model_, model_->feature_info_.silence_weighting_config, 3);
if (model_->hcl_fst_) {
json::JSON obj;
obj = json::JSON::Load(grammar);
if (obj.length() <= 0) {
KALDI_WARN << "Expecting array of strings, got: '" << grammar << "'";
} else {
KALDI_LOG << obj;
LanguageModelOptions opts;
opts.ngram_order = 2;
opts.discount = 0.5;
LanguageModelEstimator estimator(opts);
for (int i = 0; i < obj.length(); i++) {
bool ok;
string line = obj[i].ToString(ok);
if (!ok) {
KALDI_ERR << "Expecting array of strings, got: '" << obj << "'";
}
std::vector<int32> sentence;
stringstream ss(line);
string token;
while (getline(ss, token, ' ')) {
int32 id = model_->word_syms_->Find(token);
if (id == kNoSymbol) {
KALDI_WARN << "Ignoring word missing in vocabulary: '" << token << "'";
} else {
sentence.push_back(id);
}
}
estimator.AddCounts(sentence);
}
g_fst_ = new StdVectorFst();
estimator.Estimate(g_fst_);
decode_fst_ = LookaheadComposeFst(*model_->hcl_fst_, *g_fst_, model_->disambig_);
}
UpdateGrammarFst(grammar);
} else {
KALDI_WARN << "Runtime graphs are not supported by this model";
}
@@ -267,6 +229,96 @@ void Recognizer::SetSpkModel(SpkModel *spk_model)
spk_feature_ = new OnlineMfcc(spk_model_->spkvector_mfcc_opts);
}
void Recognizer::SetGrm(char const *grammar)
{
if (state_ == RECOGNIZER_RUNNING) {
KALDI_ERR << "Can't add speaker model to already running recognizer";
return;
}
if (!model_->hcl_fst_) {
KALDI_WARN << "Runtime graphs are not supported by this model";
return;
}
delete decode_fst_;
if (!strcmp(grammar, "[]")) {
decode_fst_ = LookaheadComposeFst(*model_->hcl_fst_, *model_->g_fst_, model_->disambig_);
} else {
UpdateGrammarFst(grammar);
}
samples_round_start_ += samples_processed_;
samples_processed_ = 0;
frame_offset_ = 0;
delete decoder_;
delete feature_pipeline_;
delete silence_weighting_;
silence_weighting_ = new kaldi::OnlineSilenceWeighting(*model_->trans_model_, model_->feature_info_.silence_weighting_config, 3);
feature_pipeline_ = new kaldi::OnlineNnet2FeaturePipeline (model_->feature_info_);
decoder_ = new kaldi::SingleUtteranceNnet3IncrementalDecoder(model_->nnet3_decoding_config_,
*model_->trans_model_,
*model_->decodable_info_,
*decode_fst_,
feature_pipeline_);
if (spk_model_) {
delete spk_feature_;
spk_feature_ = new OnlineMfcc(spk_model_->spkvector_mfcc_opts);
}
state_ = RECOGNIZER_INITIALIZED;
}
void Recognizer::UpdateGrammarFst(char const *grammar)
{
json::JSON obj;
obj = json::JSON::Load(grammar);
if (obj.length() <= 0) {
KALDI_WARN << "Expecting array of strings, got: '" << grammar << "'";
return;
}
KALDI_LOG << obj;
LanguageModelOptions opts;
opts.ngram_order = 2;
opts.discount = 0.5;
LanguageModelEstimator estimator(opts);
for (int i = 0; i < obj.length(); i++) {
bool ok;
string line = obj[i].ToString(ok);
if (!ok) {
KALDI_ERR << "Expecting array of strings, got: '" << obj << "'";
}
std::vector<int32> sentence;
stringstream ss(line);
string token;
while (getline(ss, token, ' ')) {
int32 id = model_->word_syms_->Find(token);
if (id == kNoSymbol) {
KALDI_WARN << "Ignoring word missing in vocabulary: '" << token << "'";
} else {
sentence.push_back(id);
}
}
estimator.AddCounts(sentence);
}
g_fst_ = new StdVectorFst();
estimator.Estimate(g_fst_);
decode_fst_ = LookaheadComposeFst(*model_->hcl_fst_, *g_fst_, model_->disambig_);
}
bool Recognizer::AcceptWaveform(const char *data, int len)
{
Vector<BaseFloat> wave;
@@ -418,14 +470,23 @@ bool Recognizer::GetSpkVector(Vector<BaseFloat> &out_xvector, int *num_spk_frame
return true;
}
// If we can't align, we still need to prepare for MBR
static void CopyLatticeForMbr(CompactLattice &lat, CompactLattice *lat_out)
{
*lat_out = lat;
RmEpsilon(lat_out, true);
fst::CreateSuperFinal(lat_out);
TopSortCompactLatticeIfNeeded(lat_out);
}
const char *Recognizer::MbrResult(CompactLattice &rlat)
{
CompactLattice aligned_lat;
if (model_->winfo_) {
WordAlignLattice(rlat, *model_->trans_model_, *model_->winfo_, 0, &aligned_lat);
} else {
aligned_lat = rlat;
CopyLatticeForMbr(rlat, &aligned_lat);
}
MinimumBayesRisk mbr(aligned_lat);
@@ -739,7 +800,11 @@ const char* Recognizer::PartialResult()
CompactLattice aligned_lat;
clat = decoder_->GetLattice(decoder_->NumFramesInLattice(), false);
WordAlignLatticePartial(clat, *model_->trans_model_, *model_->winfo_, 0, &aligned_lat);
if (model_->winfo_) {
WordAlignLatticePartial(clat, *model_->trans_model_, *model_->winfo_, 0, &aligned_lat);
} else {
CopyLatticeForMbr(clat, &aligned_lat);
}
MinimumBayesRisk mbr(aligned_lat);
const vector<BaseFloat> &conf = mbr.GetOneBestConfidences();
+2
View File
@@ -48,6 +48,7 @@ class Recognizer {
~Recognizer();
void SetMaxAlternatives(int max_alternatives);
void SetSpkModel(SpkModel *spk_model);
void SetGrm(char const *grammar);
void SetWords(bool words);
void SetPartialWords(bool partial_words);
void SetNLSML(bool nlsml);
@@ -64,6 +65,7 @@ class Recognizer {
void InitRescoring();
void CleanUp();
void UpdateSilenceWeights();
void UpdateGrammarFst(char const *grammar);
bool AcceptWaveform(Vector<BaseFloat> &wdata);
bool GetSpkVector(Vector<BaseFloat> &out_xvector, int *frames);
const char *GetResult();
+10 -2
View File
@@ -121,6 +121,14 @@ void vosk_recognizer_set_spk_model(VoskRecognizer *recognizer, VoskSpkModel *spk
((Recognizer *)recognizer)->SetSpkModel((SpkModel *)spk_model);
}
void vosk_recognizer_set_grm(VoskRecognizer *recognizer, char const *grammar)
{
if (recognizer == nullptr) {
return;
}
((Recognizer *)recognizer)->SetGrm(grammar);
}
int vosk_recognizer_accept_waveform(VoskRecognizer *recognizer, const char *data, int length)
{
try {
@@ -195,10 +203,10 @@ void vosk_gpu_thread_init()
#endif
}
VoskBatchModel *vosk_batch_model_new()
VoskBatchModel *vosk_batch_model_new(const char *model_path)
{
#if HAVE_CUDA
return (VoskBatchModel *)(new BatchModel());
return (VoskBatchModel *)(new BatchModel(model_path));
#else
return NULL;
#endif
+11 -2
View File
@@ -146,6 +146,15 @@ VoskRecognizer *vosk_recognizer_new_grm(VoskModel *model, float sample_rate, con
void vosk_recognizer_set_spk_model(VoskRecognizer *recognizer, VoskSpkModel *spk_model);
/** Reconfigures recognizer to use grammar
*
* @param recognizer Already running VoskRecognizer
* @param grammar Set of phrases in JSON array of strings or "[]" to use default model graph.
* See also vosk_recognizer_new_grm
*/
void vosk_recognizer_set_grm(VoskRecognizer *recognizer, char const *grammar);
/** Configures recognizer to output n-best results
*
* <pre>
@@ -243,7 +252,7 @@ int vosk_recognizer_accept_waveform_f(VoskRecognizer *recognizer, const float *d
* }
* </pre>
*
* If alternatives enabled it returns result with alternatives, see also vosk_recognizer_set_alternatives().
* If alternatives enabled it returns result with alternatives, see also vosk_recognizer_set_max_alternatives().
*
* If word times enabled returns word time, see also vosk_recognizer_set_word_times().
*/
@@ -310,7 +319,7 @@ void vosk_gpu_thread_init();
/** Creates the batch recognizer object
*
* @returns model object or NULL if problem occured */
VoskBatchModel *vosk_batch_model_new();
VoskBatchModel *vosk_batch_model_new(const char *model_path);
/** Releases batch model object */
void vosk_batch_model_free(VoskBatchModel *model);
-1
View File
@@ -1 +0,0 @@
../../../librispeech/s5/local/data_prep.sh
+85
View File
@@ -0,0 +1,85 @@
#!/usr/bin/env bash
# Copyright 2014 Vassil Panayotov
# 2014 Johns Hopkins University (author: Daniel Povey)
# Apache 2.0
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <src-dir> <dst-dir>"
echo "e.g.: $0 /export/a15/vpanayotov/data/LibriSpeech/dev-clean data/dev-clean"
exit 1
fi
src=$1
dst=$2
# all utterances are FLAC compressed
if ! which flac >&/dev/null; then
echo "Please install 'flac' on ALL worker nodes!"
exit 1
fi
spk_file=$src/../SPEAKERS.TXT
mkdir -p $dst || exit 1;
[ ! -d $src ] && echo "$0: no such directory $src" && exit 1;
[ ! -f $spk_file ] && echo "$0: expected file $spk_file to exist" && exit 1;
wav_scp=$dst/wav.scp; [[ -f "$wav_scp" ]] && rm $wav_scp
trans=$dst/text; [[ -f "$trans" ]] && rm $trans
utt2spk=$dst/utt2spk; [[ -f "$utt2spk" ]] && rm $utt2spk
spk2gender=$dst/spk2gender; [[ -f $spk2gender ]] && rm $spk2gender
for reader_dir in $(find -L $src -mindepth 1 -maxdepth 1 -type d | sort); do
reader=$(basename $reader_dir)
if ! [ $reader -eq $reader ]; then # not integer.
echo "$0: unexpected subdirectory name $reader"
exit 1;
fi
reader_gender=$(egrep "^$reader[ ]+\|" $spk_file | awk -F'|' '{gsub(/[ ]+/, ""); print tolower($2)}')
if [ "$reader_gender" != 'm' ] && [ "$reader_gender" != 'f' ]; then
echo "Unexpected gender: '$reader_gender'"
exit 1;
fi
for chapter_dir in $(find -L $reader_dir/ -mindepth 1 -maxdepth 1 -type d | sort); do
chapter=$(basename $chapter_dir)
if ! [ "$chapter" -eq "$chapter" ]; then
echo "$0: unexpected chapter-subdirectory name $chapter"
exit 1;
fi
find -L $chapter_dir/ -iname "*.flac" | sort | xargs -I% basename % .flac | \
awk -v "dir=$chapter_dir" '{printf "%s flac -c -d -s %s/%s.flac |\n", $0, dir, $0}' >>$wav_scp|| exit 1
chapter_trans=$chapter_dir/${reader}-${chapter}.trans.txt
[ ! -f $chapter_trans ] && echo "$0: expected file $chapter_trans to exist" && exit 1
cat $chapter_trans >>$trans
# NOTE: For now we are using per-chapter utt2spk. That is each chapter is considered
# to be a different speaker. This is done for simplicity and because we want
# e.g. the CMVN to be calculated per-chapter
awk -v "reader=$reader" -v "chapter=$chapter" '{printf "%s %s-%s\n", $1, reader, chapter}' \
<$chapter_trans >>$utt2spk || exit 1
# reader -> gender map (again using per-chapter granularity)
echo "${reader}-${chapter} $reader_gender" >>$spk2gender
done
done
spk2utt=$dst/spk2utt
utils/utt2spk_to_spk2utt.pl <$utt2spk >$spk2utt || exit 1
ntrans=$(wc -l <$trans)
nutt2spk=$(wc -l <$utt2spk)
! [ "$ntrans" -eq "$nutt2spk" ] && \
echo "Inconsistent #transcripts($ntrans) and #utt2spk($nutt2spk)" && exit 1;
utils/validate_data_dir.sh --no-feats $dst || exit 1;
echo "$0: successfully prepared data in $dst"
exit 0
+9 -7
View File
@@ -3,11 +3,13 @@
. ./cmd.sh
. ./path.sh
stage=0
stage=-1
stop_stage=100
. utils/parse_options.sh
# Data preparation
if [ $stage -le 0 ]; then
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
data_url=www.openslr.org/resources/31
lm_url=www.openslr.org/resources/11
database=corpus
@@ -24,13 +26,13 @@ if [ $stage -le 0 ]; then
fi
# Dictionary formatting
if [ $stage -le 1 ]; then
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
local/prepare_dict.sh data/local/lm data/local/dict
utils/prepare_lang.sh data/local/dict "<UNK>" data/local/lang data/lang
fi
# Extract MFCC features
if [ $stage -le 2 ]; then
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
for task in train; do
steps/make_mfcc.sh --cmd "$train_cmd" --nj 10 data/$task exp/make_mfcc/$task $mfcc
steps/compute_cmvn_stats.sh data/$task exp/make_mfcc/$task $mfcc
@@ -38,7 +40,7 @@ if [ $stage -le 2 ]; then
fi
# Train GMM models
if [ $stage -le 3 ]; then
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then
steps/train_mono.sh --nj 10 --cmd "$train_cmd" \
data/train data/lang exp/mono
@@ -65,12 +67,12 @@ if [ $stage -le 3 ]; then
fi
# Train TDNN model
if [ $stage -le 4 ]; then
if [ ${stage} -le 4 ] && [ ${stop_stage} -ge 4 ]; then
local/chain/run_tdnn.sh
fi
# Decode
if [ $stage -le 5 ]; then
if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then
utils/format_lm.sh data/lang data/local/lm/lm_tgsmall.arpa.gz data/local/dict/lexicon.txt data/lang_test
utils/mkgraph.sh --self-loop-scale 1.0 data/lang_test exp/chain/tdnn exp/chain/tdnn/graph
+1 -1
View File
@@ -29,7 +29,7 @@ RUN cd /opt \
&& git clone -b v3.2.1 --single-branch https://github.com/alphacep/clapack \
&& echo ${OPENBLAS_ARGS} \
&& make -C OpenBLAS ONLY_CBLAS=1 ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 all \
&& make -C OpenBLAS PREFIX=$(pwd)/OpenBLAS/install install \
&& make -C OpenBLAS ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 PREFIX=$(pwd)/OpenBLAS/install install \
&& mkdir -p clapack/BUILD && cd clapack/BUILD && cmake .. \
&& make -j 10 -C F2CLIBS \
&& make -j 10 -C BLAS \
+39
View File
@@ -0,0 +1,39 @@
ARG DOCKCROSS_IMAGE=dockcross/manylinux2014-aarch64
FROM ${DOCKCROSS_IMAGE}
LABEL description="A docker image for building portable Python linux binary wheels and Kaldi on other architectures"
LABEL maintainer="contact@alphacephei.com"
RUN yum -y install \
automake \
autoconf \
libtool \
libffi-devel \
&& yum clean all
ARG OPENBLAS_ARGS=
RUN cd /opt \
&& git clone -b vosk --single-branch https://github.com/alphacep/kaldi \
&& cd kaldi/tools \
&& git clone -b v0.3.20 --single-branch https://github.com/xianyi/OpenBLAS \
&& git clone -b v3.2.1 --single-branch https://github.com/alphacep/clapack \
&& echo ${OPENBLAS_ARGS} \
&& make -C OpenBLAS ONLY_CBLAS=1 ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 all \
&& make -C OpenBLAS ${OPENBLAS_ARGS} HOSTCC=gcc USE_LOCKING=1 USE_THREAD=0 PREFIX=$(pwd)/OpenBLAS/install install \
&& mkdir -p clapack/BUILD && cd clapack/BUILD && cmake .. \
&& make -j 10 -C F2CLIBS \
&& make -j 10 -C BLAS \
&& make -j 10 -C SRC \
&& find . -name "*.a" | xargs cp -t ../../OpenBLAS/install/lib \
&& cd /opt/kaldi/tools \
&& git clone --single-branch https://github.com/alphacep/openfst openfst \
&& cd openfst \
&& autoreconf -i \
&& CFLAGS="-g -O3" ./configure --prefix=/opt/kaldi/tools/openfst --enable-static --enable-shared --enable-far --enable-ngram-fsts --enable-lookahead-fsts --with-pic --disable-bin --host=${CROSS_TRIPLE} --build=x86-linux-gnu \
&& make -j 10 && make install \
&& cd /opt/kaldi/src \
&& sed -i "s:TARGET_ARCH=\"\`uname -m\`\":TARGET_ARCH=$(echo $CROSS_TRIPLE|cut -d - -f 1):g" configure \
&& sed -i "s: -O1 : -O3 :g" makefiles/linux_openblas_arm.mk \
&& ./configure --mathlib=OPENBLAS_CLAPACK --shared --use-cuda=no \
&& make -j 10 online2 lm rnnlm \
&& find /opt/kaldi -name "*.o" -exec rm {} \;
+1
View File
@@ -9,6 +9,7 @@ RUN yum -y update && yum -y install \
autoconf \
libtool \
cmake \
libffi-devel \
&& yum clean all
RUN cd /opt \
+1 -1
View File
@@ -1,4 +1,4 @@
FROM debian:10.4
FROM debian:11
RUN apt-get update && \
apt-get install -y --no-install-recommends \
+1 -1
View File
@@ -1,4 +1,4 @@
FROM debian:10.4
FROM debian:11
RUN apt-get update && \
apt-get install -y --no-install-recommends \
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
set -x
docker build --build-arg="DOCKCROSS_IMAGE=dockcross/manylinux2014-aarch64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross-manylinux --tag alphacep/kaldi-dockcross-aarch64:latest .
docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-aarch64 /io/travis/build-wheels-dockcross.sh
+6 -2
View File
@@ -4,9 +4,13 @@ set -e
set -x
docker build --build-arg="DOCKCROSS_IMAGE=alphacep/dockcross-linux-armv7" --build-arg="OPENBLAS_ARGS=TARGET=ARMV7" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-armv7:latest .
docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-arm64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-arm64:latest .
docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-x86" --build-arg="OPENBLAS_ARGS=TARGET=CORE2\ DYNAMIC_ARCH=1" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-x86:latest .
docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-riscv64" --build-arg="OPENBLAS_ARGS=TARGET=RISCV64_GENERIC\ ARCH=riscv64" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-riscv:latest .
docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-armv7 /io/travis/build-wheels-dockcross.sh
docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-arm64 /io/travis/build-wheels-dockcross.sh
docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-x86 /io/travis/build-wheels-dockcross.sh
docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-riscv /io/travis/build-wheels-dockcross.sh
# We use manylinux (Centos-based image) for aarch64 instead
# docker build --build-arg="DOCKCROSS_IMAGE=dockcross/linux-arm64" --build-arg="OPENBLAS_ARGS=TARGET=ARMV8" --file Dockerfile.dockcross --tag alphacep/kaldi-dockcross-arm64:latest .
# docker run --rm -v /home/shmyrev/travis/vosk-api/:/io alphacep/kaldi-dockcross-arm64 /io/travis/build-wheels-dockcross.sh
+15 -8
View File
@@ -11,20 +11,27 @@ KALDI_ROOT=/opt/kaldi EXTRA_LDFLAGS="-latomic" make -j $(nproc)
export VOSK_SOURCE=/opt/vosk-api
case $CROSS_TRIPLE in
*armv7-*)
export VOSK_ARCHITECTURE=armv7l
;;
*aarch64-*)
export VOSK_ARCHITECTURE=aarch64
export VOSK_MACHINE=armv7l
export VOSK_ARCHITECTURE=32bit
;;
*i686-*)
export VOSK_ARCHITECTURE=x86
export VOSK_MACHINE=x86
export VOSK_ARCHITECTURE=32bit
;;
*aarch64-*)
export VOSK_MACHINE=aarch64
export VOSK_ARCHITECTURE=64bit
;;
*riscv64-*)
export VOSK_MACHINE=riscv64
export VOSK_ARCHITECTURE=64bit
;;
esac
# Copy library to output folder
mkdir -p /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE
cp /opt/vosk-api/src/*.so /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vosk-linux-$VOSK_ARCHITECTURE
mkdir -p /io/wheelhouse/vosk-linux-$VOSK_MACHINE
cp /opt/vosk-api/src/*.so /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vosk-linux-$VOSK_MACHINE
# Build wheel
python3 -m pip install requests tqdm
python3 -m pip install requests tqdm srt websockets wheel
python3 -m pip wheel /opt/vosk-api/python --no-deps -w /io/wheelhouse
+1 -1
View File
@@ -18,6 +18,6 @@ cp /opt/vosk-api/src/*.{dll,lib} /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vos
# Build wheel and put to the output folder
export VOSK_SOURCE=/opt/vosk-api
export VOSK_PLATFORM=Windows
export VOSK_SYSTEM=Windows
export VOSK_ARCHITECTURE=64bit
python3 -m pip -v wheel /opt/vosk-api/python --no-deps -w /io/wheelhouse
+1 -1
View File
@@ -18,6 +18,6 @@ cp /opt/vosk-api/src/*.{dll,lib} /opt/vosk-api/src/vosk_api.h /io/wheelhouse/vos
# Build wheel and put to the output folder
export VOSK_SOURCE=/opt/vosk-api
export VOSK_PLATFORM=Windows
export VOSK_SYSTEM=Windows
export VOSK_ARCHITECTURE=32bit
python3 -m pip -v wheel /opt/vosk-api/python --no-deps -w /io/wheelhouse
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "vosk-js",
"version": "0.3.41",
"version": "0.3.45",
"description": "Node binding for continuous voice recoginition through vosk-api.",
"repository": {
"type": "git",