From fdab45965c4a71057cb7edb41f6fe00e2feee06a Mon Sep 17 00:00:00 2001 From: Fedor Ignatov Date: Mon, 20 Apr 2020 16:25:33 +0300 Subject: [PATCH] refactor: change base64 encoding/decoding registry naming (#1184) * refactor: base64 encoding/decoding registry renaming * docs: fix mistakes in nemo documentation --- deeppavlov/configs/nemo/asr_tts.json | 4 ++-- deeppavlov/core/common/registry.json | 4 ++-- deeppavlov/models/nemo/common.py | 4 ++-- docs/features/models/nemo.rst | 10 +++++----- tests/test_configs/nemo/tts2asr_test.json | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/deeppavlov/configs/nemo/asr_tts.json b/deeppavlov/configs/nemo/asr_tts.json index 3cb01515cf..5335bb463f 100644 --- a/deeppavlov/configs/nemo/asr_tts.json +++ b/deeppavlov/configs/nemo/asr_tts.json @@ -3,7 +3,7 @@ "in": "speech_in_encoded", "pipe": [ { - "class_name": "base64_encode_bytesIO", + "class_name": "base64_decode_bytesIO", "in": ["speech_in_encoded"], "out": ["speech_in"] }, @@ -22,7 +22,7 @@ "out": ["speech_out"] }, { - "class_name": "bytesIO_decode_base64", + "class_name": "bytesIO_encode_base64", "in": ["speech_out"], "out": ["speech_out_encoded"] } diff --git a/deeppavlov/core/common/registry.json b/deeppavlov/core/common/registry.json index 969a648348..75908a0654 100644 --- a/deeppavlov/core/common/registry.json +++ b/deeppavlov/core/common/registry.json @@ -6,7 +6,7 @@ "api_router": "deeppavlov.models.api_requester.api_router:ApiRouter", "basic_classification_iterator": "deeppavlov.dataset_iterators.basic_classification_iterator:BasicClassificationDatasetIterator", "basic_classification_reader": "deeppavlov.dataset_readers.basic_classification_reader:BasicClassificationDatasetReader", - "base64_encode_bytesIO": "deeppavlov.models.nemo.common:ascii_to_bytes_io", + "base64_decode_bytesIO": "deeppavlov.models.nemo.common:ascii_to_bytes_io", "bert_as_summarizer": "deeppavlov.models.bert.bert_as_summarizer:BertAsSummarizer", "bert_classifier": "deeppavlov.models.bert.bert_classifier:BertClassifierModel", "bert_ner_preprocessor": "deeppavlov.models.preprocessors.bert_preprocessor:BertNerPreprocessor", @@ -23,7 +23,7 @@ "bilstm_gru_nn": "deeppavlov.models.ranking.bilstm_gru_siamese_network:BiLSTMGRUSiameseNetwork", "bilstm_nn": "deeppavlov.models.ranking.bilstm_siamese_network:BiLSTMSiameseNetwork", "bow": "deeppavlov.models.embedders.bow_embedder:BoWEmbedder", - "bytesIO_decode_base64": "deeppavlov.models.nemo.common:bytes_io_to_ascii", + "bytesIO_encode_base64": "deeppavlov.models.nemo.common:bytes_io_to_ascii", "capitalization_featurizer": "deeppavlov.models.preprocessors.capitalization:CapitalizationPreprocessor", "char_splitter": "deeppavlov.models.preprocessors.char_splitter:CharSplitter", "char_splitting_lowercase_preprocessor": "deeppavlov.models.preprocessors.capitalization:CharSplittingLowercasePreprocessor", diff --git a/deeppavlov/models/nemo/common.py b/deeppavlov/models/nemo/common.py index 4fe2898195..883483c5d6 100644 --- a/deeppavlov/models/nemo/common.py +++ b/deeppavlov/models/nemo/common.py @@ -32,7 +32,7 @@ log = getLogger(__name__) -@register('base64_encode_bytesIO') +@register('base64_decode_bytesIO') def ascii_to_bytes_io(batch: Union[str, list]) -> Union[BytesIO, list]: """Recursively searches for strings in the input batch and converts them into the base64-encoded bytes wrapped in Binary I/O objects. @@ -50,7 +50,7 @@ def ascii_to_bytes_io(batch: Union[str, list]) -> Union[BytesIO, list]: return list(map(ascii_to_bytes_io, batch)) -@register('bytesIO_decode_base64') +@register('bytesIO_encode_base64') def bytes_io_to_ascii(batch: Union[BytesIO, list]) -> Union[str, list]: """Recursively searches for Binary I/O objects in the input batch and converts them into ASCII-strings. diff --git a/docs/features/models/nemo.rst b/docs/features/models/nemo.rst index 2024ee56e5..bfa3bd4421 100644 --- a/docs/features/models/nemo.rst +++ b/docs/features/models/nemo.rst @@ -41,8 +41,8 @@ above. ``labels`` is a list of characters used in TTS model training. Audio encoding end decoding. ---------------------------- -:class:`~deeppavlov.models.nemo.common.ascii_to_bytes_io` and :class:`~deeppavlov.models.nemo.common.bytes_io_to_ascii` -was added to the library to achieve uniformity at work with both text and audio data. Classes can be used to encode +:func:`~deeppavlov.models.nemo.common.ascii_to_bytes_io` and :func:`~deeppavlov.models.nemo.common.bytes_io_to_ascii` +was added to the library to achieve uniformity at work with both text and audio data. Components can be used to encode binary data to ascii string and decode back. Quck Start @@ -58,9 +58,9 @@ Install requirements and download model files. python -m deeppavlov install asr_tts python -m deeppavlov download asr_tts -Examples below use `soundservice `_ library. Install -it with ``pip install soundservice==0.3.15``. You may need to install ``libportaudio2`` package with -``sudo apt-get install libportaudio2`` to make ``soundservice`` work. +Examples below use `sounddevice `_ library. Install +it with ``pip install sounddevice==0.3.15``. You may need to install ``libportaudio2`` package with +``sudo apt-get install libportaudio2`` to make ``sounddevice`` work. .. note:: ASR reads and TTS generates single channel WAV files. Files transferred to ASR are resampled to the frequency diff --git a/tests/test_configs/nemo/tts2asr_test.json b/tests/test_configs/nemo/tts2asr_test.json index a054239e8d..22bc170143 100644 --- a/tests/test_configs/nemo/tts2asr_test.json +++ b/tests/test_configs/nemo/tts2asr_test.json @@ -10,12 +10,12 @@ "out": ["speech"] }, { - "class_name": "bytesIO_decode_base64", + "class_name": "bytesIO_encode_base64", "in": ["speech"], "out": ["ascii"] }, { - "class_name": "base64_encode_bytesIO", + "class_name": "base64_decode_bytesIO", "in": ["ascii"], "out": ["speech_restored"] },