Python rename
This commit is contained in:
parent
b86a92a5b3
commit
5449f21a47
@ -17,14 +17,14 @@ if platform.system().lower() == "windows":
|
|||||||
# directory for the dynamic linker
|
# directory for the dynamic linker
|
||||||
os.environ['PATH'] = dslib_path + ';' + os.environ['PATH']
|
os.environ['PATH'] = dslib_path + ';' + os.environ['PATH']
|
||||||
|
|
||||||
import mozilla_voice_stt
|
import mozilla_voice_stt as stt
|
||||||
|
|
||||||
# rename for backwards compatibility
|
# rename for backwards compatibility
|
||||||
from mozilla_voice_stt.impl import Version as version
|
from stt.impl import Version as version
|
||||||
|
|
||||||
class Model(object):
|
class Model(object):
|
||||||
"""
|
"""
|
||||||
Class holding a DeepSpeech model
|
Class holding a Mozilla Voice STT model
|
||||||
|
|
||||||
:param aModelPath: Path to model file to load
|
:param aModelPath: Path to model file to load
|
||||||
:type aModelPath: str
|
:type aModelPath: str
|
||||||
@ -33,14 +33,14 @@ class Model(object):
|
|||||||
# make sure the attribute is there if CreateModel fails
|
# make sure the attribute is there if CreateModel fails
|
||||||
self._impl = None
|
self._impl = None
|
||||||
|
|
||||||
status, impl = mozilla_voice_stt.impl.CreateModel(model_path)
|
status, impl = stt.impl.CreateModel(model_path)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
raise RuntimeError("CreateModel failed with '{}' (0x{:X})".format(mozilla_voice_stt.impl.ErrorCodeToErrorMessage(status),status))
|
raise RuntimeError("CreateModel failed with '{}' (0x{:X})".format(stt.impl.ErrorCodeToErrorMessage(status),status))
|
||||||
self._impl = impl
|
self._impl = impl
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if self._impl:
|
if self._impl:
|
||||||
mozilla_voice_stt.impl.FreeModel(self._impl)
|
stt.impl.FreeModel(self._impl)
|
||||||
self._impl = None
|
self._impl = None
|
||||||
|
|
||||||
def beamWidth(self):
|
def beamWidth(self):
|
||||||
@ -51,7 +51,7 @@ class Model(object):
|
|||||||
:return: Beam width value used by the model.
|
:return: Beam width value used by the model.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.GetModelBeamWidth(self._impl)
|
return stt.impl.GetModelBeamWidth(self._impl)
|
||||||
|
|
||||||
def setBeamWidth(self, beam_width):
|
def setBeamWidth(self, beam_width):
|
||||||
"""
|
"""
|
||||||
@ -63,7 +63,7 @@ class Model(object):
|
|||||||
:return: Zero on success, non-zero on failure.
|
:return: Zero on success, non-zero on failure.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.SetModelBeamWidth(self._impl, beam_width)
|
return stt.impl.SetModelBeamWidth(self._impl, beam_width)
|
||||||
|
|
||||||
def sampleRate(self):
|
def sampleRate(self):
|
||||||
"""
|
"""
|
||||||
@ -72,7 +72,7 @@ class Model(object):
|
|||||||
:return: Sample rate.
|
:return: Sample rate.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.GetModelSampleRate(self._impl)
|
return stt.impl.GetModelSampleRate(self._impl)
|
||||||
|
|
||||||
def enableExternalScorer(self, scorer_path):
|
def enableExternalScorer(self, scorer_path):
|
||||||
"""
|
"""
|
||||||
@ -83,9 +83,9 @@ class Model(object):
|
|||||||
|
|
||||||
:throws: RuntimeError on error
|
:throws: RuntimeError on error
|
||||||
"""
|
"""
|
||||||
status = mozilla_voice_stt.impl.EnableExternalScorer(self._impl, scorer_path)
|
status = stt.impl.EnableExternalScorer(self._impl, scorer_path)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
raise RuntimeError("EnableExternalScorer failed with '{}' (0x{:X})".format(mozilla_voice_stt.impl.ErrorCodeToErrorMessage(status),status))
|
raise RuntimeError("EnableExternalScorer failed with '{}' (0x{:X})".format(stt.impl.ErrorCodeToErrorMessage(status),status))
|
||||||
|
|
||||||
def disableExternalScorer(self):
|
def disableExternalScorer(self):
|
||||||
"""
|
"""
|
||||||
@ -93,7 +93,7 @@ class Model(object):
|
|||||||
|
|
||||||
:return: Zero on success, non-zero on failure.
|
:return: Zero on success, non-zero on failure.
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.DisableExternalScorer(self._impl)
|
return stt.impl.DisableExternalScorer(self._impl)
|
||||||
|
|
||||||
def setScorerAlphaBeta(self, alpha, beta):
|
def setScorerAlphaBeta(self, alpha, beta):
|
||||||
"""
|
"""
|
||||||
@ -108,11 +108,11 @@ class Model(object):
|
|||||||
:return: Zero on success, non-zero on failure.
|
:return: Zero on success, non-zero on failure.
|
||||||
:type: int
|
:type: int
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.SetScorerAlphaBeta(self._impl, alpha, beta)
|
return stt.impl.SetScorerAlphaBeta(self._impl, alpha, beta)
|
||||||
|
|
||||||
def stt(self, audio_buffer):
|
def stt(self, audio_buffer):
|
||||||
"""
|
"""
|
||||||
Use the DeepSpeech model to perform Speech-To-Text.
|
Use the Mozilla Voice STT model to perform Speech-To-Text.
|
||||||
|
|
||||||
:param audio_buffer: A 16-bit, mono raw audio signal at the appropriate sample rate (matching what the model was trained on).
|
:param audio_buffer: A 16-bit, mono raw audio signal at the appropriate sample rate (matching what the model was trained on).
|
||||||
:type audio_buffer: numpy.int16 array
|
:type audio_buffer: numpy.int16 array
|
||||||
@ -120,11 +120,11 @@ class Model(object):
|
|||||||
:return: The STT result.
|
:return: The STT result.
|
||||||
:type: str
|
:type: str
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.SpeechToText(self._impl, audio_buffer)
|
return stt.impl.SpeechToText(self._impl, audio_buffer)
|
||||||
|
|
||||||
def sttWithMetadata(self, audio_buffer, num_results=1):
|
def sttWithMetadata(self, audio_buffer, num_results=1):
|
||||||
"""
|
"""
|
||||||
Use the DeepSpeech model to perform Speech-To-Text and return results including metadata.
|
Use the Mozilla Voice STT model to perform Speech-To-Text and return results including metadata.
|
||||||
|
|
||||||
:param audio_buffer: A 16-bit, mono raw audio signal at the appropriate sample rate (matching what the model was trained on).
|
:param audio_buffer: A 16-bit, mono raw audio signal at the appropriate sample rate (matching what the model was trained on).
|
||||||
:type audio_buffer: numpy.int16 array
|
:type audio_buffer: numpy.int16 array
|
||||||
@ -135,7 +135,7 @@ class Model(object):
|
|||||||
:return: Metadata object containing multiple candidate transcripts. Each transcript has per-token metadata including timing information.
|
:return: Metadata object containing multiple candidate transcripts. Each transcript has per-token metadata including timing information.
|
||||||
:type: :func:`Metadata`
|
:type: :func:`Metadata`
|
||||||
"""
|
"""
|
||||||
return mozilla_voice_stt.impl.SpeechToTextWithMetadata(self._impl, audio_buffer, num_results)
|
return stt.impl.SpeechToTextWithMetadata(self._impl, audio_buffer, num_results)
|
||||||
|
|
||||||
def createStream(self):
|
def createStream(self):
|
||||||
"""
|
"""
|
||||||
@ -147,15 +147,15 @@ class Model(object):
|
|||||||
|
|
||||||
:throws: RuntimeError on error
|
:throws: RuntimeError on error
|
||||||
"""
|
"""
|
||||||
status, ctx = mozilla_voice_stt.impl.CreateStream(self._impl)
|
status, ctx = stt.impl.CreateStream(self._impl)
|
||||||
if status != 0:
|
if status != 0:
|
||||||
raise RuntimeError("CreateStream failed with '{}' (0x{:X})".format(mozilla_voice_stt.impl.ErrorCodeToErrorMessage(status),status))
|
raise RuntimeError("CreateStream failed with '{}' (0x{:X})".format(stt.impl.ErrorCodeToErrorMessage(status),status))
|
||||||
return Stream(ctx)
|
return Stream(ctx)
|
||||||
|
|
||||||
|
|
||||||
class Stream(object):
|
class Stream(object):
|
||||||
"""
|
"""
|
||||||
Class wrapping a DeepSpeech stream. The constructor cannot be called directly.
|
Class wrapping a Mozilla Voice STT stream. The constructor cannot be called directly.
|
||||||
Use :func:`Model.createStream()`
|
Use :func:`Model.createStream()`
|
||||||
"""
|
"""
|
||||||
def __init__(self, native_stream):
|
def __init__(self, native_stream):
|
||||||
@ -176,7 +176,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to feed an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to feed an already finished stream?")
|
||||||
mozilla_voice_stt.impl.FeedAudioContent(self._impl, audio_buffer)
|
stt.impl.FeedAudioContent(self._impl, audio_buffer)
|
||||||
|
|
||||||
def intermediateDecode(self):
|
def intermediateDecode(self):
|
||||||
"""
|
"""
|
||||||
@ -189,7 +189,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to decode an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to decode an already finished stream?")
|
||||||
return mozilla_voice_stt.impl.IntermediateDecode(self._impl)
|
return stt.impl.IntermediateDecode(self._impl)
|
||||||
|
|
||||||
def intermediateDecodeWithMetadata(self, num_results=1):
|
def intermediateDecodeWithMetadata(self, num_results=1):
|
||||||
"""
|
"""
|
||||||
@ -205,7 +205,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to decode an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to decode an already finished stream?")
|
||||||
return mozilla_voice_stt.impl.IntermediateDecodeWithMetadata(self._impl, num_results)
|
return stt.impl.IntermediateDecodeWithMetadata(self._impl, num_results)
|
||||||
|
|
||||||
def finishStream(self):
|
def finishStream(self):
|
||||||
"""
|
"""
|
||||||
@ -220,7 +220,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to finish an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to finish an already finished stream?")
|
||||||
result = mozilla_voice_stt.impl.FinishStream(self._impl)
|
result = stt.impl.FinishStream(self._impl)
|
||||||
self._impl = None
|
self._impl = None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to finish an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to finish an already finished stream?")
|
||||||
result = mozilla_voice_stt.impl.FinishStreamWithMetadata(self._impl, num_results)
|
result = stt.impl.FinishStreamWithMetadata(self._impl, num_results)
|
||||||
self._impl = None
|
self._impl = None
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@ -254,7 +254,7 @@ class Stream(object):
|
|||||||
"""
|
"""
|
||||||
if not self._impl:
|
if not self._impl:
|
||||||
raise RuntimeError("Stream object is not valid. Trying to free an already finished stream?")
|
raise RuntimeError("Stream object is not valid. Trying to free an already finished stream?")
|
||||||
mozilla_voice_stt.impl.FreeStream(self._impl)
|
stt.impl.FreeStream(self._impl)
|
||||||
self._impl = None
|
self._impl = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ import sys
|
|||||||
import wave
|
import wave
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from mozilla_voice_stt import Model, version
|
import mozilla_voice_stt as stt
|
||||||
from timeit import default_timer as timer
|
from timeit import default_timer as timer
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -83,7 +83,7 @@ class VersionAction(argparse.Action):
|
|||||||
super(VersionAction, self).__init__(nargs=0, *args, **kwargs)
|
super(VersionAction, self).__init__(nargs=0, *args, **kwargs)
|
||||||
|
|
||||||
def __call__(self, *args, **kwargs):
|
def __call__(self, *args, **kwargs):
|
||||||
print('Mozilla Voice STT ', version())
|
print('Mozilla Voice STT ', stt.version())
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
|
||||||
@ -114,7 +114,7 @@ def main():
|
|||||||
print('Loading model from file {}'.format(args.model), file=sys.stderr)
|
print('Loading model from file {}'.format(args.model), file=sys.stderr)
|
||||||
model_load_start = timer()
|
model_load_start = timer()
|
||||||
# sphinx-doc: python_ref_model_start
|
# sphinx-doc: python_ref_model_start
|
||||||
ds = Model(args.model)
|
ds = stt.Model(args.model)
|
||||||
# sphinx-doc: python_ref_model_stop
|
# sphinx-doc: python_ref_model_stop
|
||||||
model_load_end = timer() - model_load_start
|
model_load_end = timer() - model_load_start
|
||||||
print('Loaded model in {:.3}s.'.format(model_load_end), file=sys.stderr)
|
print('Loaded model in {:.3}s.'.format(model_load_end), file=sys.stderr)
|
||||||
|
@ -67,7 +67,7 @@ def main():
|
|||||||
swig_opts=['-c++', '-keyword'])
|
swig_opts=['-c++', '-keyword'])
|
||||||
|
|
||||||
setup(name=project_name,
|
setup(name=project_name,
|
||||||
description='A library for running inference on a DeepSpeech model',
|
description='A library for running inference on a Mozilla Voice STT model',
|
||||||
long_description=read('README.rst'),
|
long_description=read('README.rst'),
|
||||||
long_description_content_type='text/x-rst; charset=UTF-8',
|
long_description_content_type='text/x-rst; charset=UTF-8',
|
||||||
author='Mozilla',
|
author='Mozilla',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user