processing_clvp.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding=utf-8
  2. # Copyright 2023 The HuggingFace Inc. team.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """
  16. Processor class for CLVP
  17. """
  18. from ...processing_utils import ProcessorMixin
  19. from ...utils import logging
  20. logger = logging.get_logger(__name__)
  21. class ClvpProcessor(ProcessorMixin):
  22. r"""
  23. Constructs a CLVP processor which wraps a CLVP Feature Extractor and a CLVP Tokenizer into a single processor.
  24. [`ClvpProcessor`] offers all the functionalities of [`ClvpFeatureExtractor`] and [`ClvpTokenizer`]. See the
  25. [`~ClvpProcessor.__call__`], [`~ClvpProcessor.decode`] and [`~ClvpProcessor.batch_decode`] for more information.
  26. Args:
  27. feature_extractor (`ClvpFeatureExtractor`):
  28. An instance of [`ClvpFeatureExtractor`]. The feature extractor is a required input.
  29. tokenizer (`ClvpTokenizer`):
  30. An instance of [`ClvpTokenizer`]. The tokenizer is a required input.
  31. """
  32. feature_extractor_class = "ClvpFeatureExtractor"
  33. tokenizer_class = "ClvpTokenizer"
  34. def __init__(self, feature_extractor, tokenizer):
  35. super().__init__(feature_extractor, tokenizer)
  36. def __call__(self, *args, **kwargs):
  37. """
  38. Forwards the `audio` and `sampling_rate` arguments to [`~ClvpFeatureExtractor.__call__`] and the `text`
  39. argument to [`~ClvpTokenizer.__call__`]. Please refer to the docstring of the above two methods for more
  40. information.
  41. """
  42. raw_speech = kwargs.pop("raw_speech", None)
  43. if raw_speech is not None:
  44. logger.warning(
  45. "Using `raw_speech` keyword argument is deprecated when calling ClvpProcessor, instead use `audio`."
  46. )
  47. kwargs["audio"] = raw_speech
  48. return super().__call__(*args, **kwargs)
  49. __all__ = ["ClvpProcessor"]