codingutf8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license processor class for clvp featureextractorclass clvpfeatureextractor tokenizerclass clvptokenizer modelinputnames inputids inputfeatures attentionmask def initself featureextractor tokenizer super initfeatureextractor tokenizer def callself args kwargs rawspeech kwargs poprawspeech none samplingrate kwargs popsamplingrate none text kwargs poptext none if rawspeech is none and text is none raise valueerroryou need to specify either an rawspeech or text input to process if rawspeech is not none inputs self featureextractorrawspeech samplingratesamplingrate kwargs if text is not none encodings self tokenizertext kwargs if text is none return inputs elif rawspeech is none return encodings else inputsinputids encodingsinputids inputsattentionmask encodingsattentionmask return inputs copied from transformers models whisper processingwhisper whisperprocessor batchdecode with whisperclvp def batchdecodeself args kwargs return self tokenizer batchdecodeargs kwargs copied from transformers models whisper processingwhisper whisperprocessor decode with whisperclvp def decodeself args kwargs return self tokenizer decodeargs kwargs coding utf 8 2023 the huggingface inc team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license processor class for clvp constructs a clvp processor which wraps a clvp feature extractor and a clvp tokenizer into a single processor clvpprocessor offers all the functionalities of clvpfeatureextractor and clvptokenizer see the clvpprocessor __call__ clvpprocessor decode and clvpprocessor batch_decode for more information args feature_extractor clvpfeatureextractor an instance of clvpfeatureextractor the feature extractor is a required input tokenizer clvptokenizer an instance of clvptokenizer the tokenizer is a required input forwards the audio and sampling_rate arguments to clvpfeatureextractor __call__ and the text argument to clvptokenizer __call__ please refer to the doctsring of the above two methods for more information copied from transformers models whisper processing_whisper whisperprocessor batch_decode with whisper clvp this method forwards all its arguments to clvptokenizer s pretrainedtokenizer batch_decode please refer to the docstring of this method for more information copied from transformers models whisper processing_whisper whisperprocessor decode with whisper clvp this method forwards all its arguments to clvptokenizer s pretrainedtokenizer decode please refer to the docstring of this method for more information
from ...processing_utils import ProcessorMixin


class ClvpProcessor(ProcessorMixin):
    r

    feature_extractor_class = "ClvpFeatureExtractor"
    tokenizer_class = "ClvpTokenizer"
    model_input_names = [
        "input_ids",
        "input_features",
        "attention_mask",
    ]

    def __init__(self, feature_extractor, tokenizer):
        super().__init__(feature_extractor, tokenizer)

    def __call__(self, *args, **kwargs):
        

        raw_speech = kwargs.pop("raw_speech", None)
        sampling_rate = kwargs.pop("sampling_rate", None)
        text = kwargs.pop("text", None)

        if raw_speech is None and text is None:
            raise ValueError("You need to specify either an `raw_speech` or `text` input to process.")

        if raw_speech is not None:
            inputs = self.feature_extractor(raw_speech, sampling_rate=sampling_rate, **kwargs)
        if text is not None:
            encodings = self.tokenizer(text, **kwargs)

        if text is None:
            return inputs
        elif raw_speech is None:
            return encodings
        else:
            inputs["input_ids"] = encodings["input_ids"]
            inputs["attention_mask"] = encodings["attention_mask"]
            return inputs

    
    def batch_decode(self, *args, **kwargs):
        
        return self.tokenizer.batch_decode(*args, **kwargs)

    
    def decode(self, *args, **kwargs):
        
        return self.tokenizer.decode(*args, **kwargs)