Package: vatis-asr-client
Speech recognition client for Vatis API in PythonPython implementation of the client for Vatis's ASR servicesGetting startedRequirementsPython >= 3.6InstallationCreate a free account on theVatis PlatformObtain you're privateAPI keyInstall Vatis Live ASR client:pip install "vatis_asr_client[remote]"Add your private key as environment variable:VATIS_ASR_CLIENT_API_KEY=<YOUR_API_KEY>(Optional) Configure otherenvironment variablesUsage1. Create a stream configuration objectfrom vatis.live_asr.config.stream import StreamConfig, Language, SPEED_CONFIGURATION, SampleRate, Channel, \
     DEFAULT_CONNECTION_CONFIG

stream_config: StreamConfig = StreamConfig(
        language=Language.ro_RO,
        performance_config=SPEED_CONFIGURATION,
        connection_config=DEFAULT_CONNECTION_CONFIG,
        sample_rate=SampleRate.RATE_16000,
        channels=Channel.ONE,
    )2. Create a LiveStream based on your configurationfrom vatis.live_asr.stream.factory import create_stream

with create_stream(stream_config, stream_type='BLOCKING') as stream:
    # ...3. Add a listener for the events of your streamfrom vatis.live_asr.utils.observer import FormattedLiveStreamObserver

stream.add_observer(FormattedLiveStreamObserver())4. Create your custom data generator or use any of the predefined onesfrom vatis.live_asr.utils.generator import file_generator

data_generator: Generator = file_generator('<your_wav_file_path>', stream_config)5. Pass the generator to the stream and wait until it finishesstream.transcribe(data_generator)

stream.wait_for_transcription()ExamplesStream a file using a stream observerfromtypingimportGeneratorfromvatis.live_asr.config.streamimportStreamConfig,Language,SPEED_CONFIGURATION,SampleRate,Channel,\DEFAULT_CONNECTION_CONFIGfromvatis.live_asr.loggingimportget_loggerfromvatis.live_asr.stream.factoryimportcreate_streamfromvatis.live_asr.utils.generatorimportfile_generatorfromvatis.live_asr.utils.observerimportFormattedLiveStreamObserverlogger=get_logger('main')if__name__=='__main__':stream_config:StreamConfig=StreamConfig(language=Language.ro_RO,performance_config=SPEED_CONFIGURATION,connection_config=DEFAULT_CONNECTION_CONFIG,sample_rate=SampleRate.RATE_16000,channels=Channel.ONE,)withcreate_stream(stream_config,stream_type='BLOCKING')asstream:stream.add_observer(FormattedLiveStreamObserver())data_generator:Generator=file_generator('<your_wav_file_path>',stream_config)stream.transcribe(data_generator)stream.wait_for_transcription()Streaming a file using a generatorfromtypingimportGeneratorfromvatis.live_asr.config.streamimportStreamConfig,Language,SPEED_CONFIGURATION,SampleRate,Channel,\DEFAULT_CONNECTION_CONFIGfromvatis.live_asr.loggingimportget_loggerfromvatis.live_asr.stream.factoryimportcreate_streamfromvatis.live_asr.utils.generatorimportfile_generatorlogger=get_logger('main')if__name__=='__main__':stream_config:StreamConfig=StreamConfig(language=Language.ro_RO,performance_config=SPEED_CONFIGURATION,connection_config=DEFAULT_CONNECTION_CONFIG,sample_rate=SampleRate.RATE_16000,channels=Channel.ONE,)withcreate_stream(stream_config,stream_type='BLOCKING')asstream:data_generator:Generator=file_generator('<your_wav_file_path>',stream_config)stream.transcribe(data_generator)forresponseinstream.create_generator():logger.info(response.transcript)Infinite stream from the microphone using stream observersfromtypingimportGeneratorfromvatis.live_asr.config.streamimportStreamConfig,Language,SPEED_CONFIGURATION,SampleRate,Channel,\DEFAULT_CONNECTION_CONFIGfromvatis.live_asr.stream.factoryimportcreate_streamfromvatis.live_asr.utils.generatorimportmicrophone_generatorfromvatis.live_asr.utils.observerimportFormattedLiveStreamObserverif__name__=='__main__':stream_config:StreamConfig=StreamConfig(language=Language.ro_RO,performance_config=SPEED_CONFIGURATION,connection_config=DEFAULT_CONNECTION_CONFIG,sample_rate=SampleRate.RATE_16000,channels=Channel.ONE,)withcreate_stream(stream_config,stream_type='BLOCKING')asstream:stream.add_observer(FormattedLiveStreamObserver())data_generator:Generator=microphone_generator(stream_config)stream.transcribe(data_generator)stream.wait_for_transcription()Stream from the microphone a specified amount of time using generatorsimportsysfromtypingimportGeneratorfromvatis.asr_commons.live.headersimportFINAL_FRAME_HEADER,FRAME_START_TIME_HEADER,FRAME_END_TIME_HEADERfromvatis.live_asr.config.streamimportStreamConfig,Language,SPEED_CONFIGURATION,SampleRate,Channel,\DEFAULT_CONNECTION_CONFIGfromvatis.live_asr.stream.factoryimportcreate_streamfromvatis.live_asr.utils.generatorimportmicrophone_generatorif__name__=='__main__':stream_config:StreamConfig=StreamConfig(language=Language.ro_RO,performance_config=SPEED_CONFIGURATION,connection_config=DEFAULT_CONNECTION_CONFIG,sample_rate=SampleRate.RATE_16000,channels=Channel.ONE,)out=sys.stdouttime_limit:float=0.5*60defstop_condition(frame_count:int,starting_time:dict)->bool:transcribed_time=stream_config.performance_config.frame_len*frame_countreturntranscribed_time>=time_limitwithcreate_stream(stream_config,stream_type='BLOCKING')asstream:data_generator:Generator=microphone_generator(stream_config,stop_condition=stop_condition)stream.transcribe(data_generator)forpacketinstream.create_generator():ifpacket.get_header(FINAL_FRAME_HEADER,default=False):out.write('FINAL  :{0:.2f}->{1:.2f}:{2}\n'.format(packet.get_header(FRAME_START_TIME_HEADER),packet.get_header(FRAME_END_TIME_HEADER),packet.transcript))out.flush()else:out.write('PARTIAL:{0:.2f}->{1:.2f}:{2}\r'.format(packet.get_header(FRAME_START_TIME_HEADER),packet.get_header(FRAME_END_TIME_HEADER),packet.transcript))out.flush()Infinite stream from the microphone using stream observers and saving the output to a filefrom typing import Generator

from vatis.live_asr.config.stream import StreamConfig, Language, SPEED_CONFIGURATION, SampleRate, Channel, \
    DEFAULT_CONNECTION_CONFIG
from vatis.live_asr.stream.factory import create_stream
from vatis.live_asr.utils.generator import microphone_generator
from vatis.live_asr.utils.observer import FormattedLiveStreamObserver

if __name__ == '__main__':
    stream_config: StreamConfig = StreamConfig(
        language=Language.ro_RO,
        performance_config=SPEED_CONFIGURATION,
        connection_config=DEFAULT_CONNECTION_CONFIG,
        sample_rate=SampleRate.RATE_16000,
        channels=Channel.ONE
    )

    output_transcription_file: str = 'path/to/your/output_transcription.txt'

    with create_stream(stream_config, stream_type='BLOCKING') as stream:
        with open(output_transcription_file, 'w') as out:
            stream.add_observer(FormattedLiveStreamObserver())  # writes the transcript to stdout
            stream.add_observer(FormattedLiveStreamObserver(out, only_finals=True))  # writes the transcript to the output file

            data_generator: Generator = microphone_generator(stream_config)

            stream.transcribe(data_generator)

            stream.wait_for_transcription()Custom modelsUse a pre-defined model for a specific languagefrom vatis.live_asr.config.stream import StreamConfig, Language, SPEED_CONFIGURATION, SampleRate, Channel, \
     DEFAULT_CONNECTION_CONFIG
from vatis.asr_commons.custom_models import ro_RO

stream_config: StreamConfig = StreamConfig(
        language=Language.ro_RO,
        performance_config=SPEED_CONFIGURATION,
        connection_config=DEFAULT_CONNECTION_CONFIG,
        sample_rate=SampleRate.RATE_16000,
        channels=Channel.ONE,
        model=ro_RO.MEDIA
)Use your own custom model.Contact usfor details about how to build your own custom model.from vatis.live_asr.config.stream import StreamConfig, Language, SPEED_CONFIGURATION, SampleRate, Channel, \
     DEFAULT_CONNECTION_CONFIG

stream_config: StreamConfig = StreamConfig(
        language=Language.ro_RO,
        performance_config=SPEED_CONFIGURATION,
        connection_config=DEFAULT_CONNECTION_CONFIG,
        sample_rate=SampleRate.RATE_16000,
        channels=Channel.ONE,
        model='00000000-0000-0000-0000-000000000000'
)Environment variablesVariableTypeDefault valueDescriptionVATIS_ASR_CLIENT_DEBUGboolFalseDebug flag for more loggingVATIS_ASR_CLIENT_RECONNECTION_ATTEMPTSint6Maximum connection attempts to the ASR serviceVATIS_ASR_CLIENT_REQUEST_TIMEOUT_SECONDSfloat15Timeout of an attempt to make a request to the serverVATIS_ASR_CLIENT_RECONNECTION_DELAY_SECONDSfloat5Delay between two reconnection attemptsVATIS_ASR_CLIENT_CONNECTION_TIMEOUT_SECONDSfloat10Timeout of a connection attemptVATIS_ASR_CLIENT_SERVICE_HOSTstringa5111be014375425f9cfe48e23715c8c-6ed9fe3966df7ef3.elb.eu-central-1.amazonaws.comASR service host nameVATIS_ASR_CLIENT_SERVICE_PORTint80ASR service port numberVATIS_ASR_CLIENT_AUTHENTICATION_PROVIDER_URLstringhttps://vatis.tech/api/v1/asr-client/authAuthentication end-pointVATIS_ASR_CLIENT_API_KEYstringPrivate API key for ASR service accessVATIS_ASR_CLIENT_LOGS_FILEstringlogs/app.logsPath for storing log filesVATIS_ASR_CLIENT_ENABLE_LOGS_FILEboolFalseFlag for enabling logs storing inside files