diff --git a/ibm_watson/assistant_v2.py b/ibm_watson/assistant_v2.py index 32d898ab..72dbd34c 100644 --- a/ibm_watson/assistant_v2.py +++ b/ibm_watson/assistant_v2.py @@ -1,6 +1,6 @@ # coding: utf-8 -# (C) Copyright IBM Corp. 2019, 2025. +# (C) Copyright IBM Corp. 2019, 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -4677,6 +4677,88 @@ def __ne__(self, other: 'DialogSuggestionValue') -> bool: return not self == other +class DtmfCommandInfo: + """ + DtmfCommandInfo. + + :param str type: Specifies the type of DTMF command for the phone integration. + :param dict parameters: (optional) Parameters specified by the command type. + """ + + def __init__( + self, + type: str, + *, + parameters: Optional[dict] = None, + ) -> None: + """ + Initialize a DtmfCommandInfo object. + + :param str type: Specifies the type of DTMF command for the phone + integration. + :param dict parameters: (optional) Parameters specified by the command + type. + """ + self.type = type + self.parameters = parameters + + @classmethod + def from_dict(cls, _dict: Dict) -> 'DtmfCommandInfo': + """Initialize a DtmfCommandInfo object from a json dictionary.""" + args = {} + if (type := _dict.get('type')) is not None: + args['type'] = type + else: + raise ValueError( + 'Required property \'type\' not present in DtmfCommandInfo JSON' + ) + if (parameters := _dict.get('parameters')) is not None: + args['parameters'] = parameters + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a DtmfCommandInfo object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'type') and self.type is not None: + _dict['type'] = self.type + if hasattr(self, 'parameters') and self.parameters is not None: + _dict['parameters'] = self.parameters + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this DtmfCommandInfo object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'DtmfCommandInfo') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'DtmfCommandInfo') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class TypeEnum(str, Enum): + """ + Specifies the type of DTMF command for the phone integration. + """ + + COLLECT = 'collect' + DISABLE_BARGE_IN = 'disable_barge_in' + ENABLE_BARGE_IN = 'enable_barge_in' + SEND = 'send' + + class Environment: """ Environment. @@ -12107,7 +12189,9 @@ def __init__(self,) -> None: 'RuntimeResponseGenericRuntimeResponseTypeVideo', 'RuntimeResponseGenericRuntimeResponseTypeAudio', 'RuntimeResponseGenericRuntimeResponseTypeIframe', - 'RuntimeResponseGenericRuntimeResponseTypeDate' + 'RuntimeResponseGenericRuntimeResponseTypeDate', + 'RuntimeResponseGenericRuntimeResponseTypeDtmf', + 'RuntimeResponseGenericRuntimeResponseTypeEndSession' ])) raise Exception(msg) @@ -12132,7 +12216,9 @@ def from_dict(cls, _dict: Dict) -> 'RuntimeResponseGeneric': 'RuntimeResponseGenericRuntimeResponseTypeVideo', 'RuntimeResponseGenericRuntimeResponseTypeAudio', 'RuntimeResponseGenericRuntimeResponseTypeIframe', - 'RuntimeResponseGenericRuntimeResponseTypeDate' + 'RuntimeResponseGenericRuntimeResponseTypeDate', + 'RuntimeResponseGenericRuntimeResponseTypeDtmf', + 'RuntimeResponseGenericRuntimeResponseTypeEndSession' ])) raise Exception(msg) @@ -12163,6 +12249,9 @@ def _get_class_by_discriminator(cls, _dict: Dict) -> object: mapping[ 'user_defined'] = 'RuntimeResponseGenericRuntimeResponseTypeUserDefined' mapping['video'] = 'RuntimeResponseGenericRuntimeResponseTypeVideo' + mapping['dtmf'] = 'RuntimeResponseGenericRuntimeResponseTypeDtmf' + mapping[ + 'end_session'] = 'RuntimeResponseGenericRuntimeResponseTypeEndSession' disc_value = _dict.get('response_type') if disc_value is None: raise ValueError( @@ -21888,6 +21977,191 @@ def __ne__(self, return not self == other +class RuntimeResponseGenericRuntimeResponseTypeDtmf(RuntimeResponseGeneric): + """ + RuntimeResponseGenericRuntimeResponseTypeDtmf. + + :param str response_type: The type of response returned by the dialog node. The + specified response type must be supported by the client application or channel. + :param DtmfCommandInfo command_info: (optional) + :param List[ResponseGenericChannel] channels: (optional) An array of objects + specifying channels for which the response is intended. If **channels** is + present, the response is intended for a built-in integration and should not be + handled by an API client. + """ + + def __init__( + self, + response_type: str, + *, + command_info: Optional['DtmfCommandInfo'] = None, + channels: Optional[List['ResponseGenericChannel']] = None, + ) -> None: + """ + Initialize a RuntimeResponseGenericRuntimeResponseTypeDtmf object. + + :param str response_type: The type of response returned by the dialog node. + The specified response type must be supported by the client application or + channel. + :param DtmfCommandInfo command_info: (optional) + :param List[ResponseGenericChannel] channels: (optional) An array of + objects specifying channels for which the response is intended. If + **channels** is present, the response is intended for a built-in + integration and should not be handled by an API client. + """ + # pylint: disable=super-init-not-called + self.response_type = response_type + self.command_info = command_info + self.channels = channels + + @classmethod + def from_dict( + cls, + _dict: Dict) -> 'RuntimeResponseGenericRuntimeResponseTypeDtmf': + """Initialize a RuntimeResponseGenericRuntimeResponseTypeDtmf object from a json dictionary.""" + args = {} + if (response_type := _dict.get('response_type')) is not None: + args['response_type'] = response_type + else: + raise ValueError( + 'Required property \'response_type\' not present in RuntimeResponseGenericRuntimeResponseTypeDtmf JSON' + ) + if (command_info := _dict.get('command_info')) is not None: + args['command_info'] = DtmfCommandInfo.from_dict(command_info) + if (channels := _dict.get('channels')) is not None: + args['channels'] = [ + ResponseGenericChannel.from_dict(v) for v in channels + ] + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a RuntimeResponseGenericRuntimeResponseTypeDtmf object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'response_type') and self.response_type is not None: + _dict['response_type'] = self.response_type + if hasattr(self, 'command_info') and self.command_info is not None: + if isinstance(self.command_info, dict): + _dict['command_info'] = self.command_info + else: + _dict['command_info'] = self.command_info.to_dict() + if hasattr(self, 'channels') and self.channels is not None: + channels_list = [] + for v in self.channels: + if isinstance(v, dict): + channels_list.append(v) + else: + channels_list.append(v.to_dict()) + _dict['channels'] = channels_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this RuntimeResponseGenericRuntimeResponseTypeDtmf object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, + other: 'RuntimeResponseGenericRuntimeResponseTypeDtmf') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, + other: 'RuntimeResponseGenericRuntimeResponseTypeDtmf') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class RuntimeResponseGenericRuntimeResponseTypeEndSession( + RuntimeResponseGeneric): + """ + RuntimeResponseGenericRuntimeResponseTypeEndSession. + + :param str response_type: The type of response returned by the dialog node. The + specified response type must be supported by the client application or channel. + :param dict channel_options: (optional) For internal use only. + """ + + def __init__( + self, + response_type: str, + *, + channel_options: Optional[dict] = None, + ) -> None: + """ + Initialize a RuntimeResponseGenericRuntimeResponseTypeEndSession object. + + :param str response_type: The type of response returned by the dialog node. + The specified response type must be supported by the client application or + channel. + :param dict channel_options: (optional) For internal use only. + """ + # pylint: disable=super-init-not-called + self.response_type = response_type + self.channel_options = channel_options + + @classmethod + def from_dict( + cls, _dict: Dict + ) -> 'RuntimeResponseGenericRuntimeResponseTypeEndSession': + """Initialize a RuntimeResponseGenericRuntimeResponseTypeEndSession object from a json dictionary.""" + args = {} + if (response_type := _dict.get('response_type')) is not None: + args['response_type'] = response_type + else: + raise ValueError( + 'Required property \'response_type\' not present in RuntimeResponseGenericRuntimeResponseTypeEndSession JSON' + ) + if (channel_options := _dict.get('channel_options')) is not None: + args['channel_options'] = channel_options + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a RuntimeResponseGenericRuntimeResponseTypeEndSession object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'response_type') and self.response_type is not None: + _dict['response_type'] = self.response_type + if hasattr(self, + 'channel_options') and self.channel_options is not None: + _dict['channel_options'] = self.channel_options + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this RuntimeResponseGenericRuntimeResponseTypeEndSession object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__( + self, other: 'RuntimeResponseGenericRuntimeResponseTypeEndSession' + ) -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__( + self, other: 'RuntimeResponseGenericRuntimeResponseTypeEndSession' + ) -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class RuntimeResponseGenericRuntimeResponseTypeIframe(RuntimeResponseGeneric): """ RuntimeResponseGenericRuntimeResponseTypeIframe. diff --git a/ibm_watson/speech_to_text_v1.py b/ibm_watson/speech_to_text_v1.py index 64e60064..1b1b47bc 100644 --- a/ibm_watson/speech_to_text_v1.py +++ b/ibm_watson/speech_to_text_v1.py @@ -1,6 +1,6 @@ # coding: utf-8 -# (C) Copyright IBM Corp. 2015, 2025. +# (C) Copyright IBM Corp. 2015, 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -197,6 +197,7 @@ def recognize( content_type: Optional[str] = None, model: Optional[str] = None, speech_begin_event: Optional[bool] = None, + enrichments: Optional[str] = None, language_customization_id: Optional[str] = None, acoustic_customization_id: Optional[str] = None, base_model_version: Optional[str] = None, @@ -356,6 +357,16 @@ def recognize( `sad_module: 2` to increase accuracy and performance in detecting speech boundaries within the audio stream. See [Using speech recognition parameters](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-service-features#features-parameters). + :param str enrichments: (optional) Speech transcript enrichment improves + readability of raw ASR transcripts by adding punctuation (periods, commas, + question marks, exclamation points) and intelligent capitalization + (sentence beginnings, proper nouns, acronyms, brand names). To enable + enrichment, add the `enrichments=punctuation` parameter to your recognition + request. Supported languages include English (US, UK, Australia, India), + French (France, Canada), German, Italian, Portuguese (Brazil, Portugal), + Spanish (Spain, Latin America, Argentina, Chile, Colombia, Mexico, Peru), + and Japanese. See [Speech transcript + enrichment](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-speech-transcript-enrichment). :param str language_customization_id: (optional) The customization ID (GUID) of a custom language model that is to be used with the recognition request. The base model of the specified custom language model must match @@ -634,6 +645,7 @@ def recognize( params = { 'model': model, 'speech_begin_event': speech_begin_event, + 'enrichments': enrichments, 'language_customization_id': language_customization_id, 'acoustic_customization_id': acoustic_customization_id, 'base_model_version': base_model_version, @@ -831,6 +843,8 @@ def create_job( events: Optional[str] = None, user_token: Optional[str] = None, results_ttl: Optional[int] = None, + speech_begin_event: Optional[bool] = None, + enrichments: Optional[str] = None, language_customization_id: Optional[str] = None, acoustic_customization_id: Optional[str] = None, base_model_version: Optional[str] = None, @@ -1031,6 +1045,25 @@ def create_job( via a callback, the results must be retrieved within this time. Omit the parameter to use a time to live of one week. The parameter is valid with or without a callback URL. + :param bool speech_begin_event: (optional) If `true`, the service returns a + response object `SpeechActivity` which contains the time when a speech + activity is detected in the stream. This can be used both in standard and + low latency mode. This feature enables client applications to know that + some words/speech has been detected and the service is in the process of + decoding. This can be used in lieu of interim results in standard mode. Use + `sad_module: 2` to increase accuracy and performance in detecting speech + boundaries within the audio stream. See [Using speech recognition + parameters](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-service-features#features-parameters). + :param str enrichments: (optional) Speech transcript enrichment improves + readability of raw ASR transcripts by adding punctuation (periods, commas, + question marks, exclamation points) and intelligent capitalization + (sentence beginnings, proper nouns, acronyms, brand names). To enable + enrichment, add the `enrichments=punctuation` parameter to your recognition + request. Supported languages include English (US, UK, Australia, India), + French (France, Canada), German, Italian, Portuguese (Brazil, Portugal), + Spanish (Spain, Latin America, Argentina, Chile, Colombia, Mexico, Peru), + and Japanese. See [Speech transcript + enrichment](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-speech-transcript-enrichment). :param str language_customization_id: (optional) The customization ID (GUID) of a custom language model that is to be used with the recognition request. The base model of the specified custom language model must match @@ -1334,6 +1367,8 @@ def create_job( 'events': events, 'user_token': user_token, 'results_ttl': results_ttl, + 'speech_begin_event': speech_begin_event, + 'enrichments': enrichments, 'language_customization_id': language_customization_id, 'acoustic_customization_id': acoustic_customization_id, 'base_model_version': base_model_version, @@ -4311,6 +4346,75 @@ def delete_user_data( response = self.send(request, **kwargs) return response + ######################### + # Language identification + ######################### + + def detect_language( + self, + lid_confidence: float, + audio: BinaryIO, + *, + content_type: Optional[str] = None, + **kwargs, + ) -> DetailedResponse: + """ + Spoken language identification. + + Detects the spoken language in audio streams. The endpoint is + `/v1/detect_language` and user can optionally include `lid_confidence` parameter + to set a custom confidence threshold for detection. The model continuously + processes incoming audio and returns the identified language when it reaches a + confidence level higher than the specified threshold (0.99 by default). See + [Spoken language + identification](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-speech-language-identification). + + :param float lid_confidence: Set a custom confidence threshold for + detection. + :param BinaryIO audio: The audio to transcribe. + :param str content_type: (optional) The type of the input. + :param dict headers: A `dict` containing the request headers + :return: A `DetailedResponse` containing the result, headers and HTTP status code. + :rtype: DetailedResponse with `dict` result representing a `LanguageDetectionResults` object + """ + + if lid_confidence is None: + raise ValueError('lid_confidence must be provided') + if audio is None: + raise ValueError('audio must be provided') + headers = { + 'Content-Type': content_type, + } + sdk_headers = get_sdk_headers( + service_name=self.DEFAULT_SERVICE_NAME, + service_version='V1', + operation_id='detect_language', + ) + headers.update(sdk_headers) + + params = { + 'lid_confidence': lid_confidence, + } + + data = audio + + if 'headers' in kwargs: + headers.update(kwargs.get('headers')) + del kwargs['headers'] + headers['Accept'] = 'application/json' + + url = '/v1/detect_language' + request = self.prepare_request( + method='POST', + url=url, + headers=headers, + params=params, + data=data, + ) + + response = self.send(request, **kwargs) + return response + class GetModelEnums: """ @@ -4933,6 +5037,34 @@ class ContainedContentType(str, Enum): AUDIO_WEBM_CODECS_VORBIS = 'audio/webm;codecs=vorbis' +class DetectLanguageEnums: + """ + Enums for detect_language parameters. + """ + + class ContentType(str, Enum): + """ + The type of the input. + """ + + APPLICATION_OCTET_STREAM = 'application/octet-stream' + AUDIO_ALAW = 'audio/alaw' + AUDIO_BASIC = 'audio/basic' + AUDIO_FLAC = 'audio/flac' + AUDIO_G729 = 'audio/g729' + AUDIO_L16 = 'audio/l16' + AUDIO_MP3 = 'audio/mp3' + AUDIO_MPEG = 'audio/mpeg' + AUDIO_MULAW = 'audio/mulaw' + AUDIO_OGG = 'audio/ogg' + AUDIO_OGG_CODECS_OPUS = 'audio/ogg;codecs=opus' + AUDIO_OGG_CODECS_VORBIS = 'audio/ogg;codecs=vorbis' + AUDIO_WAV = 'audio/wav' + AUDIO_WEBM = 'audio/webm' + AUDIO_WEBM_CODECS_OPUS = 'audio/webm;codecs=opus' + AUDIO_WEBM_CODECS_VORBIS = 'audio/webm;codecs=vorbis' + + ############################################################################## # Models ############################################################################## @@ -6593,6 +6725,224 @@ def __ne__(self, other: 'CustomWord') -> bool: return not self == other +class EnrichedResults: + """ + If enriched results are requested, transcription with inserted punctuation marks such + as periods, commas, question marks, and exclamation points. + + :param EnrichedResultsTranscript transcript: (optional) If enriched results are + requested, transcription with inserted punctuation marks such as periods, + commas, question marks, and exclamation points. + :param str status: (optional) The status of the enriched transcription. + """ + + def __init__( + self, + *, + transcript: Optional['EnrichedResultsTranscript'] = None, + status: Optional[str] = None, + ) -> None: + """ + Initialize a EnrichedResults object. + + :param EnrichedResultsTranscript transcript: (optional) If enriched results + are requested, transcription with inserted punctuation marks such as + periods, commas, question marks, and exclamation points. + :param str status: (optional) The status of the enriched transcription. + """ + self.transcript = transcript + self.status = status + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnrichedResults': + """Initialize a EnrichedResults object from a json dictionary.""" + args = {} + if (transcript := _dict.get('transcript')) is not None: + args['transcript'] = EnrichedResultsTranscript.from_dict(transcript) + if (status := _dict.get('status')) is not None: + args['status'] = status + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnrichedResults object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'transcript') and self.transcript is not None: + if isinstance(self.transcript, dict): + _dict['transcript'] = self.transcript + else: + _dict['transcript'] = self.transcript.to_dict() + if hasattr(self, 'status') and self.status is not None: + _dict['status'] = self.status + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnrichedResults object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnrichedResults') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnrichedResults') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class EnrichedResultsTranscript: + """ + If enriched results are requested, transcription with inserted punctuation marks such + as periods, commas, question marks, and exclamation points. + + :param str text: (optional) The transcript text. + :param EnrichedResultsTranscriptTimestamp timestamp: (optional) The speaking + time from the beginning of the transcript to the end. + """ + + def __init__( + self, + *, + text: Optional[str] = None, + timestamp: Optional['EnrichedResultsTranscriptTimestamp'] = None, + ) -> None: + """ + Initialize a EnrichedResultsTranscript object. + + :param str text: (optional) The transcript text. + :param EnrichedResultsTranscriptTimestamp timestamp: (optional) The + speaking time from the beginning of the transcript to the end. + """ + self.text = text + self.timestamp = timestamp + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnrichedResultsTranscript': + """Initialize a EnrichedResultsTranscript object from a json dictionary.""" + args = {} + if (text := _dict.get('text')) is not None: + args['text'] = text + if (timestamp := _dict.get('timestamp')) is not None: + args['timestamp'] = EnrichedResultsTranscriptTimestamp.from_dict( + timestamp) + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnrichedResultsTranscript object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'text') and self.text is not None: + _dict['text'] = self.text + if hasattr(self, 'timestamp') and self.timestamp is not None: + if isinstance(self.timestamp, dict): + _dict['timestamp'] = self.timestamp + else: + _dict['timestamp'] = self.timestamp.to_dict() + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnrichedResultsTranscript object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnrichedResultsTranscript') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnrichedResultsTranscript') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class EnrichedResultsTranscriptTimestamp: + """ + The speaking time from the beginning of the transcript to the end. + + :param float from_: (optional) The start time of a word from the transcript. The + value matches the start time of a word from the `timestamps` array. + :param float to: (optional) The end time of a word from the transcript. The + value matches the end time of a word from the `timestamps` array. + """ + + def __init__( + self, + *, + from_: Optional[float] = None, + to: Optional[float] = None, + ) -> None: + """ + Initialize a EnrichedResultsTranscriptTimestamp object. + + :param float from_: (optional) The start time of a word from the + transcript. The value matches the start time of a word from the + `timestamps` array. + :param float to: (optional) The end time of a word from the transcript. The + value matches the end time of a word from the `timestamps` array. + """ + self.from_ = from_ + self.to = to + + @classmethod + def from_dict(cls, _dict: Dict) -> 'EnrichedResultsTranscriptTimestamp': + """Initialize a EnrichedResultsTranscriptTimestamp object from a json dictionary.""" + args = {} + if (from_ := _dict.get('from')) is not None: + args['from_'] = from_ + if (to := _dict.get('to')) is not None: + args['to'] = to + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a EnrichedResultsTranscriptTimestamp object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'from_') and self.from_ is not None: + _dict['from'] = self.from_ + if hasattr(self, 'to') and self.to is not None: + _dict['to'] = self.to + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this EnrichedResultsTranscriptTimestamp object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'EnrichedResultsTranscriptTimestamp') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'EnrichedResultsTranscriptTimestamp') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class Grammar: """ Information about a grammar from a custom language model. @@ -6901,6 +7251,237 @@ def __ne__(self, other: 'KeywordResult') -> bool: return not self == other +class LanguageDetectionResult: + """ + Language detection results. + + :param List[LanguageInfo] language_info: (optional) An array of `LanguageInfo` + objects. + """ + + def __init__( + self, + *, + language_info: Optional[List['LanguageInfo']] = None, + ) -> None: + """ + Initialize a LanguageDetectionResult object. + + :param List[LanguageInfo] language_info: (optional) An array of + `LanguageInfo` objects. + """ + self.language_info = language_info + + @classmethod + def from_dict(cls, _dict: Dict) -> 'LanguageDetectionResult': + """Initialize a LanguageDetectionResult object from a json dictionary.""" + args = {} + if (language_info := _dict.get('language_info')) is not None: + args['language_info'] = [ + LanguageInfo.from_dict(v) for v in language_info + ] + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a LanguageDetectionResult object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'language_info') and self.language_info is not None: + language_info_list = [] + for v in self.language_info: + if isinstance(v, dict): + language_info_list.append(v) + else: + language_info_list.append(v.to_dict()) + _dict['language_info'] = language_info_list + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this LanguageDetectionResult object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'LanguageDetectionResult') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'LanguageDetectionResult') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class LanguageDetectionResults: + """ + Language detection results. + + :param List[LanguageDetectionResult] results: (optional) An array of + `LanguageDetectionResult` objects. + :param int result_index: (optional) An index that indicates a change point in + the `results` array. The service increments the index for additional results + that it sends for new audio for the same request. All results with the same + index are delivered at the same time. The same index can include multiple final + results that are delivered with the same response. + """ + + def __init__( + self, + *, + results: Optional[List['LanguageDetectionResult']] = None, + result_index: Optional[int] = None, + ) -> None: + """ + Initialize a LanguageDetectionResults object. + + :param List[LanguageDetectionResult] results: (optional) An array of + `LanguageDetectionResult` objects. + :param int result_index: (optional) An index that indicates a change point + in the `results` array. The service increments the index for additional + results that it sends for new audio for the same request. All results with + the same index are delivered at the same time. The same index can include + multiple final results that are delivered with the same response. + """ + self.results = results + self.result_index = result_index + + @classmethod + def from_dict(cls, _dict: Dict) -> 'LanguageDetectionResults': + """Initialize a LanguageDetectionResults object from a json dictionary.""" + args = {} + if (results := _dict.get('results')) is not None: + args['results'] = [ + LanguageDetectionResult.from_dict(v) for v in results + ] + if (result_index := _dict.get('result_index')) is not None: + args['result_index'] = result_index + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a LanguageDetectionResults object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'results') and self.results is not None: + results_list = [] + for v in self.results: + if isinstance(v, dict): + results_list.append(v) + else: + results_list.append(v.to_dict()) + _dict['results'] = results_list + if hasattr(self, 'result_index') and self.result_index is not None: + _dict['result_index'] = self.result_index + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this LanguageDetectionResults object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'LanguageDetectionResults') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'LanguageDetectionResults') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + +class LanguageInfo: + """ + Language detection info such as confidence and language detected. + + :param float confidence: (optional) A score that indicates the service's + confidence in its identification of the language in the range of 0.0 to 1.0. + :param str language: (optional) The language detected in standard abbreviated + ISO 639 format. + :param float timestamp: (optional) The timestamp of the detected language. + """ + + def __init__( + self, + *, + confidence: Optional[float] = None, + language: Optional[str] = None, + timestamp: Optional[float] = None, + ) -> None: + """ + Initialize a LanguageInfo object. + + :param float confidence: (optional) A score that indicates the service's + confidence in its identification of the language in the range of 0.0 to + 1.0. + :param str language: (optional) The language detected in standard + abbreviated ISO 639 format. + :param float timestamp: (optional) The timestamp of the detected language. + """ + self.confidence = confidence + self.language = language + self.timestamp = timestamp + + @classmethod + def from_dict(cls, _dict: Dict) -> 'LanguageInfo': + """Initialize a LanguageInfo object from a json dictionary.""" + args = {} + if (confidence := _dict.get('confidence')) is not None: + args['confidence'] = confidence + if (language := _dict.get('language')) is not None: + args['language'] = language + if (timestamp := _dict.get('timestamp')) is not None: + args['timestamp'] = timestamp + return cls(**args) + + @classmethod + def _from_dict(cls, _dict): + """Initialize a LanguageInfo object from a json dictionary.""" + return cls.from_dict(_dict) + + def to_dict(self) -> Dict: + """Return a json dictionary representing this model.""" + _dict = {} + if hasattr(self, 'confidence') and self.confidence is not None: + _dict['confidence'] = self.confidence + if hasattr(self, 'language') and self.language is not None: + _dict['language'] = self.language + if hasattr(self, 'timestamp') and self.timestamp is not None: + _dict['timestamp'] = self.timestamp + return _dict + + def _to_dict(self): + """Return a json dictionary representing this model.""" + return self.to_dict() + + def __str__(self) -> str: + """Return a `str` version of this LanguageInfo object.""" + return json.dumps(self.to_dict(), indent=2) + + def __eq__(self, other: 'LanguageInfo') -> bool: + """Return `true` when self and other are equal, false otherwise.""" + if not isinstance(other, self.__class__): + return False + return self.__dict__ == other.__dict__ + + def __ne__(self, other: 'LanguageInfo') -> bool: + """Return `true` when self and other are not equal, false otherwise.""" + return not self == other + + class LanguageModel: """ Information about an existing custom language model. @@ -8350,8 +8931,8 @@ class SpeechRecognitionResult: to be updated further. * If `false`, the results are interim. They can be updated with further interim results until final results are eventually sent. - **Note:** Because `final` is a reserved word in Java and Swift, the field is - renamed `xFinal` in Java and is escaped with back quotes in Swift. + **Note:** Because `final` is a reserved word in Java, the field is renamed + `xFinal` in Java. :param List[SpeechRecognitionAlternative] alternatives: An array of alternative transcripts. The `alternatives` array can include additional requested output such as word confidence or timestamps. @@ -8395,8 +8976,8 @@ def __init__( not to be updated further. * If `false`, the results are interim. They can be updated with further interim results until final results are eventually sent. - **Note:** Because `final` is a reserved word in Java and Swift, the field - is renamed `xFinal` in Java and is escaped with back quotes in Swift. + **Note:** Because `final` is a reserved word in Java, the field is renamed + `xFinal` in Java. :param List[SpeechRecognitionAlternative] alternatives: An array of alternative transcripts. The `alternatives` array can include additional requested output such as word confidence or timestamps. @@ -8578,6 +9159,9 @@ class SpeechRecognitionResults: do not do that you will be automatically switched to base model when you used the non-updated custom model."` In both cases, the request succeeds despite the warnings. + :param EnrichedResults enriched_results: (optional) If enriched results are + requested, transcription with inserted punctuation marks such as periods, + commas, question marks, and exclamation points. """ def __init__( @@ -8589,6 +9173,7 @@ def __init__( processing_metrics: Optional['ProcessingMetrics'] = None, audio_metrics: Optional['AudioMetrics'] = None, warnings: Optional[List[str]] = None, + enriched_results: Optional['EnrichedResults'] = None, ) -> None: """ Initialize a SpeechRecognitionResults object. @@ -8639,6 +9224,9 @@ def __init__( the new base model. If you do not do that you will be automatically switched to base model when you used the non-updated custom model."` In both cases, the request succeeds despite the warnings. + :param EnrichedResults enriched_results: (optional) If enriched results are + requested, transcription with inserted punctuation marks such as periods, + commas, question marks, and exclamation points. """ self.results = results self.result_index = result_index @@ -8646,6 +9234,7 @@ def __init__( self.processing_metrics = processing_metrics self.audio_metrics = audio_metrics self.warnings = warnings + self.enriched_results = enriched_results @classmethod def from_dict(cls, _dict: Dict) -> 'SpeechRecognitionResults': @@ -8668,6 +9257,9 @@ def from_dict(cls, _dict: Dict) -> 'SpeechRecognitionResults': args['audio_metrics'] = AudioMetrics.from_dict(audio_metrics) if (warnings := _dict.get('warnings')) is not None: args['warnings'] = warnings + if (enriched_results := _dict.get('enriched_results')) is not None: + args['enriched_results'] = EnrichedResults.from_dict( + enriched_results) return cls(**args) @classmethod @@ -8710,6 +9302,12 @@ def to_dict(self) -> Dict: _dict['audio_metrics'] = self.audio_metrics.to_dict() if hasattr(self, 'warnings') and self.warnings is not None: _dict['warnings'] = self.warnings + if hasattr(self, + 'enriched_results') and self.enriched_results is not None: + if isinstance(self.enriched_results, dict): + _dict['enriched_results'] = self.enriched_results + else: + _dict['enriched_results'] = self.enriched_results.to_dict() return _dict def _to_dict(self): diff --git a/test/unit/test_assistant_v2.py b/test/unit/test_assistant_v2.py index 21613a15..f2ab8482 100644 --- a/test/unit/test_assistant_v2.py +++ b/test/unit/test_assistant_v2.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2019, 2025. +# (C) Copyright IBM Corp. 2019, 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -6539,6 +6539,37 @@ def test_dialog_suggestion_value_serialization(self): assert dialog_suggestion_value_model_json2 == dialog_suggestion_value_model_json +class TestModel_DtmfCommandInfo: + """ + Test Class for DtmfCommandInfo + """ + + def test_dtmf_command_info_serialization(self): + """ + Test serialization/deserialization for DtmfCommandInfo + """ + + # Construct a json representation of a DtmfCommandInfo model + dtmf_command_info_model_json = {} + dtmf_command_info_model_json['type'] = 'collect' + dtmf_command_info_model_json['parameters'] = {'anyKey': 'anyValue'} + + # Construct a model instance of DtmfCommandInfo by calling from_dict on the json representation + dtmf_command_info_model = DtmfCommandInfo.from_dict(dtmf_command_info_model_json) + assert dtmf_command_info_model != False + + # Construct a model instance of DtmfCommandInfo by calling from_dict on the json representation + dtmf_command_info_model_dict = DtmfCommandInfo.from_dict(dtmf_command_info_model_json).__dict__ + dtmf_command_info_model2 = DtmfCommandInfo(**dtmf_command_info_model_dict) + + # Verify the model instances are equivalent + assert dtmf_command_info_model == dtmf_command_info_model2 + + # Convert model instance back to dict and verify no loss of data + dtmf_command_info_model_json2 = dtmf_command_info_model.to_dict() + assert dtmf_command_info_model_json2 == dtmf_command_info_model_json + + class TestModel_Environment: """ Test Class for Environment @@ -15851,6 +15882,78 @@ def test_runtime_response_generic_runtime_response_type_date_serialization(self) assert runtime_response_generic_runtime_response_type_date_model_json2 == runtime_response_generic_runtime_response_type_date_model_json +class TestModel_RuntimeResponseGenericRuntimeResponseTypeDtmf: + """ + Test Class for RuntimeResponseGenericRuntimeResponseTypeDtmf + """ + + def test_runtime_response_generic_runtime_response_type_dtmf_serialization(self): + """ + Test serialization/deserialization for RuntimeResponseGenericRuntimeResponseTypeDtmf + """ + + # Construct dict forms of any model objects needed in order to build this model. + + dtmf_command_info_model = {} # DtmfCommandInfo + dtmf_command_info_model['type'] = 'collect' + dtmf_command_info_model['parameters'] = {'anyKey': 'anyValue'} + + response_generic_channel_model = {} # ResponseGenericChannel + response_generic_channel_model['channel'] = 'testString' + + # Construct a json representation of a RuntimeResponseGenericRuntimeResponseTypeDtmf model + runtime_response_generic_runtime_response_type_dtmf_model_json = {} + runtime_response_generic_runtime_response_type_dtmf_model_json['response_type'] = 'dtmf' + runtime_response_generic_runtime_response_type_dtmf_model_json['command_info'] = dtmf_command_info_model + runtime_response_generic_runtime_response_type_dtmf_model_json['channels'] = [response_generic_channel_model] + + # Construct a model instance of RuntimeResponseGenericRuntimeResponseTypeDtmf by calling from_dict on the json representation + runtime_response_generic_runtime_response_type_dtmf_model = RuntimeResponseGenericRuntimeResponseTypeDtmf.from_dict(runtime_response_generic_runtime_response_type_dtmf_model_json) + assert runtime_response_generic_runtime_response_type_dtmf_model != False + + # Construct a model instance of RuntimeResponseGenericRuntimeResponseTypeDtmf by calling from_dict on the json representation + runtime_response_generic_runtime_response_type_dtmf_model_dict = RuntimeResponseGenericRuntimeResponseTypeDtmf.from_dict(runtime_response_generic_runtime_response_type_dtmf_model_json).__dict__ + runtime_response_generic_runtime_response_type_dtmf_model2 = RuntimeResponseGenericRuntimeResponseTypeDtmf(**runtime_response_generic_runtime_response_type_dtmf_model_dict) + + # Verify the model instances are equivalent + assert runtime_response_generic_runtime_response_type_dtmf_model == runtime_response_generic_runtime_response_type_dtmf_model2 + + # Convert model instance back to dict and verify no loss of data + runtime_response_generic_runtime_response_type_dtmf_model_json2 = runtime_response_generic_runtime_response_type_dtmf_model.to_dict() + assert runtime_response_generic_runtime_response_type_dtmf_model_json2 == runtime_response_generic_runtime_response_type_dtmf_model_json + + +class TestModel_RuntimeResponseGenericRuntimeResponseTypeEndSession: + """ + Test Class for RuntimeResponseGenericRuntimeResponseTypeEndSession + """ + + def test_runtime_response_generic_runtime_response_type_end_session_serialization(self): + """ + Test serialization/deserialization for RuntimeResponseGenericRuntimeResponseTypeEndSession + """ + + # Construct a json representation of a RuntimeResponseGenericRuntimeResponseTypeEndSession model + runtime_response_generic_runtime_response_type_end_session_model_json = {} + runtime_response_generic_runtime_response_type_end_session_model_json['response_type'] = 'end_session' + runtime_response_generic_runtime_response_type_end_session_model_json['channel_options'] = {'anyKey': 'anyValue'} + + # Construct a model instance of RuntimeResponseGenericRuntimeResponseTypeEndSession by calling from_dict on the json representation + runtime_response_generic_runtime_response_type_end_session_model = RuntimeResponseGenericRuntimeResponseTypeEndSession.from_dict(runtime_response_generic_runtime_response_type_end_session_model_json) + assert runtime_response_generic_runtime_response_type_end_session_model != False + + # Construct a model instance of RuntimeResponseGenericRuntimeResponseTypeEndSession by calling from_dict on the json representation + runtime_response_generic_runtime_response_type_end_session_model_dict = RuntimeResponseGenericRuntimeResponseTypeEndSession.from_dict(runtime_response_generic_runtime_response_type_end_session_model_json).__dict__ + runtime_response_generic_runtime_response_type_end_session_model2 = RuntimeResponseGenericRuntimeResponseTypeEndSession(**runtime_response_generic_runtime_response_type_end_session_model_dict) + + # Verify the model instances are equivalent + assert runtime_response_generic_runtime_response_type_end_session_model == runtime_response_generic_runtime_response_type_end_session_model2 + + # Convert model instance back to dict and verify no loss of data + runtime_response_generic_runtime_response_type_end_session_model_json2 = runtime_response_generic_runtime_response_type_end_session_model.to_dict() + assert runtime_response_generic_runtime_response_type_end_session_model_json2 == runtime_response_generic_runtime_response_type_end_session_model_json + + class TestModel_RuntimeResponseGenericRuntimeResponseTypeIframe: """ Test Class for RuntimeResponseGenericRuntimeResponseTypeIframe diff --git a/test/unit/test_speech_to_text_v1.py b/test/unit/test_speech_to_text_v1.py index 348bbb6c..cb5babf8 100644 --- a/test/unit/test_speech_to_text_v1.py +++ b/test/unit/test_speech_to_text_v1.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# (C) Copyright IBM Corp. 2025. +# (C) Copyright IBM Corp. 2026. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -204,7 +204,7 @@ def test_recognize_all_params(self): """ # Set up mock url = preprocess_url('/v1/recognize') - mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}' + mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}' responses.add( responses.POST, url, @@ -218,6 +218,7 @@ def test_recognize_all_params(self): content_type = 'application/octet-stream' model = 'en-US_BroadbandModel' speech_begin_event = False + enrichments = 'testString' language_customization_id = 'testString' acoustic_customization_id = 'testString' base_model_version = 'testString' @@ -250,6 +251,7 @@ def test_recognize_all_params(self): content_type=content_type, model=model, speech_begin_event=speech_begin_event, + enrichments=enrichments, language_customization_id=language_customization_id, acoustic_customization_id=acoustic_customization_id, base_model_version=base_model_version, @@ -286,6 +288,7 @@ def test_recognize_all_params(self): query_string = urllib.parse.unquote_plus(query_string) assert 'model={}'.format(model) in query_string assert 'speech_begin_event={}'.format('true' if speech_begin_event else 'false') in query_string + assert 'enrichments={}'.format(enrichments) in query_string assert 'language_customization_id={}'.format(language_customization_id) in query_string assert 'acoustic_customization_id={}'.format(acoustic_customization_id) in query_string assert 'base_model_version={}'.format(base_model_version) in query_string @@ -324,7 +327,7 @@ def test_recognize_required_params(self): """ # Set up mock url = preprocess_url('/v1/recognize') - mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}' + mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}' responses.add( responses.POST, url, @@ -363,7 +366,7 @@ def test_recognize_value_error(self): """ # Set up mock url = preprocess_url('/v1/recognize') - mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}' + mock_response = '{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}' responses.add( responses.POST, url, @@ -626,7 +629,7 @@ def test_create_job_all_params(self): """ # Set up mock url = preprocess_url('/v1/recognitions') - mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}' + mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}' responses.add( responses.POST, url, @@ -643,6 +646,8 @@ def test_create_job_all_params(self): events = 'recognitions.started' user_token = 'testString' results_ttl = 38 + speech_begin_event = False + enrichments = 'testString' language_customization_id = 'testString' acoustic_customization_id = 'testString' base_model_version = 'testString' @@ -680,6 +685,8 @@ def test_create_job_all_params(self): events=events, user_token=user_token, results_ttl=results_ttl, + speech_begin_event=speech_begin_event, + enrichments=enrichments, language_customization_id=language_customization_id, acoustic_customization_id=acoustic_customization_id, base_model_version=base_model_version, @@ -721,6 +728,8 @@ def test_create_job_all_params(self): assert 'events={}'.format(events) in query_string assert 'user_token={}'.format(user_token) in query_string assert 'results_ttl={}'.format(results_ttl) in query_string + assert 'speech_begin_event={}'.format('true' if speech_begin_event else 'false') in query_string + assert 'enrichments={}'.format(enrichments) in query_string assert 'language_customization_id={}'.format(language_customization_id) in query_string assert 'acoustic_customization_id={}'.format(acoustic_customization_id) in query_string assert 'base_model_version={}'.format(base_model_version) in query_string @@ -760,7 +769,7 @@ def test_create_job_required_params(self): """ # Set up mock url = preprocess_url('/v1/recognitions') - mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}' + mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}' responses.add( responses.POST, url, @@ -799,7 +808,7 @@ def test_create_job_value_error(self): """ # Set up mock url = preprocess_url('/v1/recognitions') - mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}' + mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}' responses.add( responses.POST, url, @@ -842,7 +851,7 @@ def test_check_jobs_all_params(self): """ # Set up mock url = preprocess_url('/v1/recognitions') - mock_response = '{"recognitions": [{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}]}' + mock_response = '{"recognitions": [{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}]}' responses.add( responses.GET, url, @@ -880,7 +889,7 @@ def test_check_job_all_params(self): """ # Set up mock url = preprocess_url('/v1/recognitions/testString') - mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}' + mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}' responses.add( responses.GET, url, @@ -918,7 +927,7 @@ def test_check_job_value_error(self): """ # Set up mock url = preprocess_url('/v1/recognitions/testString') - mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"]}], "warnings": ["warnings"]}' + mock_response = '{"id": "id", "status": "waiting", "created": "created", "updated": "updated", "url": "url", "user_token": "user_token", "results": [{"results": [{"final": false, "alternatives": [{"transcript": "transcript", "confidence": 0, "timestamps": ["timestamps"], "word_confidence": ["word_confidence"]}], "keywords_result": {"mapKey": [{"normalized_text": "normalized_text", "start_time": 10, "end_time": 8, "confidence": 0}]}, "word_alternatives": [{"start_time": 10, "end_time": 8, "alternatives": [{"confidence": 0, "word": "word"}]}], "end_of_utterance": "end_of_data"}], "result_index": 12, "speaker_labels": [{"from": 5, "to": 2, "speaker": 7, "confidence": 10, "final": false}], "processing_metrics": {"processed_audio": {"received": 8, "seen_by_engine": 14, "transcription": 13, "speaker_labels": 14}, "wall_clock_since_first_byte_received": 36, "periodic": true}, "audio_metrics": {"sampling_interval": 17, "accumulated": {"final": false, "end_time": 8, "signal_to_noise_ratio": 21, "speech_ratio": 12, "high_frequency_loss": 19, "direct_current_offset": [{"begin": 5, "end": 3, "count": 5}], "clipping_rate": [{"begin": 5, "end": 3, "count": 5}], "speech_level": [{"begin": 5, "end": 3, "count": 5}], "non_speech_level": [{"begin": 5, "end": 3, "count": 5}]}}, "warnings": ["warnings"], "enriched_results": {"transcript": {"text": "text", "timestamp": {"from": 5, "to": 2}}, "status": "status"}}], "warnings": ["warnings"]}' responses.add( responses.GET, url, @@ -4071,6 +4080,152 @@ def test_delete_user_data_value_error_with_retries(self): # End of Service: UserData ############################################################################## +############################################################################## +# Start of Service: LanguageIdentification +############################################################################## +# region + + +class TestDetectLanguage: + """ + Test Class for detect_language + """ + + @responses.activate + def test_detect_language_all_params(self): + """ + detect_language() + """ + # Set up mock + url = preprocess_url('/v1/detect_language') + mock_response = '{"results": [{"language_info": [{"confidence": 10, "language": "language", "timestamp": 9}]}], "result_index": 12}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + lid_confidence = 36.0 + audio = io.BytesIO(b'This is a mock file.').getvalue() + content_type = 'application/octet-stream' + + # Invoke method + response = _service.detect_language( + lid_confidence, + audio, + content_type=content_type, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + # Validate body params + + def test_detect_language_all_params_with_retries(self): + # Enable retries and run test_detect_language_all_params. + _service.enable_retries() + self.test_detect_language_all_params() + + # Disable retries and run test_detect_language_all_params. + _service.disable_retries() + self.test_detect_language_all_params() + + @responses.activate + def test_detect_language_required_params(self): + """ + test_detect_language_required_params() + """ + # Set up mock + url = preprocess_url('/v1/detect_language') + mock_response = '{"results": [{"language_info": [{"confidence": 10, "language": "language", "timestamp": 9}]}], "result_index": 12}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + lid_confidence = 36.0 + audio = io.BytesIO(b'This is a mock file.').getvalue() + + # Invoke method + response = _service.detect_language( + lid_confidence, + audio, + headers={}, + ) + + # Check for correct operation + assert len(responses.calls) == 1 + assert response.status_code == 200 + # Validate query params + query_string = responses.calls[0].request.url.split('?', 1)[1] + query_string = urllib.parse.unquote_plus(query_string) + # Validate body params + + def test_detect_language_required_params_with_retries(self): + # Enable retries and run test_detect_language_required_params. + _service.enable_retries() + self.test_detect_language_required_params() + + # Disable retries and run test_detect_language_required_params. + _service.disable_retries() + self.test_detect_language_required_params() + + @responses.activate + def test_detect_language_value_error(self): + """ + test_detect_language_value_error() + """ + # Set up mock + url = preprocess_url('/v1/detect_language') + mock_response = '{"results": [{"language_info": [{"confidence": 10, "language": "language", "timestamp": 9}]}], "result_index": 12}' + responses.add( + responses.POST, + url, + body=mock_response, + content_type='application/json', + status=200, + ) + + # Set up parameter values + lid_confidence = 36.0 + audio = io.BytesIO(b'This is a mock file.').getvalue() + + # Pass in all but one required param and check for a ValueError + req_param_dict = { + "lid_confidence": lid_confidence, + "audio": audio, + } + for param in req_param_dict.keys(): + req_copy = {key: val if key is not param else None for (key, val) in req_param_dict.items()} + with pytest.raises(ValueError): + _service.detect_language(**req_copy) + + def test_detect_language_value_error_with_retries(self): + # Enable retries and run test_detect_language_value_error. + _service.enable_retries() + self.test_detect_language_value_error() + + # Disable retries and run test_detect_language_value_error. + _service.disable_retries() + self.test_detect_language_value_error() + + +# endregion +############################################################################## +# End of Service: LanguageIdentification +############################################################################## + ############################################################################## # Start of Model Tests @@ -4565,6 +4720,115 @@ def test_custom_word_serialization(self): assert custom_word_model_json2 == custom_word_model_json +class TestModel_EnrichedResults: + """ + Test Class for EnrichedResults + """ + + def test_enriched_results_serialization(self): + """ + Test serialization/deserialization for EnrichedResults + """ + + # Construct dict forms of any model objects needed in order to build this model. + + enriched_results_transcript_timestamp_model = {} # EnrichedResultsTranscriptTimestamp + enriched_results_transcript_timestamp_model['from'] = 36.0 + enriched_results_transcript_timestamp_model['to'] = 36.0 + + enriched_results_transcript_model = {} # EnrichedResultsTranscript + enriched_results_transcript_model['text'] = 'testString' + enriched_results_transcript_model['timestamp'] = enriched_results_transcript_timestamp_model + + # Construct a json representation of a EnrichedResults model + enriched_results_model_json = {} + enriched_results_model_json['transcript'] = enriched_results_transcript_model + enriched_results_model_json['status'] = 'testString' + + # Construct a model instance of EnrichedResults by calling from_dict on the json representation + enriched_results_model = EnrichedResults.from_dict(enriched_results_model_json) + assert enriched_results_model != False + + # Construct a model instance of EnrichedResults by calling from_dict on the json representation + enriched_results_model_dict = EnrichedResults.from_dict(enriched_results_model_json).__dict__ + enriched_results_model2 = EnrichedResults(**enriched_results_model_dict) + + # Verify the model instances are equivalent + assert enriched_results_model == enriched_results_model2 + + # Convert model instance back to dict and verify no loss of data + enriched_results_model_json2 = enriched_results_model.to_dict() + assert enriched_results_model_json2 == enriched_results_model_json + + +class TestModel_EnrichedResultsTranscript: + """ + Test Class for EnrichedResultsTranscript + """ + + def test_enriched_results_transcript_serialization(self): + """ + Test serialization/deserialization for EnrichedResultsTranscript + """ + + # Construct dict forms of any model objects needed in order to build this model. + + enriched_results_transcript_timestamp_model = {} # EnrichedResultsTranscriptTimestamp + enriched_results_transcript_timestamp_model['from'] = 36.0 + enriched_results_transcript_timestamp_model['to'] = 36.0 + + # Construct a json representation of a EnrichedResultsTranscript model + enriched_results_transcript_model_json = {} + enriched_results_transcript_model_json['text'] = 'testString' + enriched_results_transcript_model_json['timestamp'] = enriched_results_transcript_timestamp_model + + # Construct a model instance of EnrichedResultsTranscript by calling from_dict on the json representation + enriched_results_transcript_model = EnrichedResultsTranscript.from_dict(enriched_results_transcript_model_json) + assert enriched_results_transcript_model != False + + # Construct a model instance of EnrichedResultsTranscript by calling from_dict on the json representation + enriched_results_transcript_model_dict = EnrichedResultsTranscript.from_dict(enriched_results_transcript_model_json).__dict__ + enriched_results_transcript_model2 = EnrichedResultsTranscript(**enriched_results_transcript_model_dict) + + # Verify the model instances are equivalent + assert enriched_results_transcript_model == enriched_results_transcript_model2 + + # Convert model instance back to dict and verify no loss of data + enriched_results_transcript_model_json2 = enriched_results_transcript_model.to_dict() + assert enriched_results_transcript_model_json2 == enriched_results_transcript_model_json + + +class TestModel_EnrichedResultsTranscriptTimestamp: + """ + Test Class for EnrichedResultsTranscriptTimestamp + """ + + def test_enriched_results_transcript_timestamp_serialization(self): + """ + Test serialization/deserialization for EnrichedResultsTranscriptTimestamp + """ + + # Construct a json representation of a EnrichedResultsTranscriptTimestamp model + enriched_results_transcript_timestamp_model_json = {} + enriched_results_transcript_timestamp_model_json['from'] = 36.0 + enriched_results_transcript_timestamp_model_json['to'] = 36.0 + + # Construct a model instance of EnrichedResultsTranscriptTimestamp by calling from_dict on the json representation + enriched_results_transcript_timestamp_model = EnrichedResultsTranscriptTimestamp.from_dict(enriched_results_transcript_timestamp_model_json) + assert enriched_results_transcript_timestamp_model != False + + # Construct a model instance of EnrichedResultsTranscriptTimestamp by calling from_dict on the json representation + enriched_results_transcript_timestamp_model_dict = EnrichedResultsTranscriptTimestamp.from_dict(enriched_results_transcript_timestamp_model_json).__dict__ + enriched_results_transcript_timestamp_model2 = EnrichedResultsTranscriptTimestamp(**enriched_results_transcript_timestamp_model_dict) + + # Verify the model instances are equivalent + assert enriched_results_transcript_timestamp_model == enriched_results_transcript_timestamp_model2 + + # Convert model instance back to dict and verify no loss of data + enriched_results_transcript_timestamp_model_json2 = enriched_results_transcript_timestamp_model.to_dict() + assert enriched_results_transcript_timestamp_model_json2 == enriched_results_transcript_timestamp_model_json + + class TestModel_Grammar: """ Test Class for Grammar @@ -4669,6 +4933,116 @@ def test_keyword_result_serialization(self): assert keyword_result_model_json2 == keyword_result_model_json +class TestModel_LanguageDetectionResult: + """ + Test Class for LanguageDetectionResult + """ + + def test_language_detection_result_serialization(self): + """ + Test serialization/deserialization for LanguageDetectionResult + """ + + # Construct dict forms of any model objects needed in order to build this model. + + language_info_model = {} # LanguageInfo + language_info_model['confidence'] = 36.0 + language_info_model['language'] = 'testString' + language_info_model['timestamp'] = 36.0 + + # Construct a json representation of a LanguageDetectionResult model + language_detection_result_model_json = {} + language_detection_result_model_json['language_info'] = [language_info_model] + + # Construct a model instance of LanguageDetectionResult by calling from_dict on the json representation + language_detection_result_model = LanguageDetectionResult.from_dict(language_detection_result_model_json) + assert language_detection_result_model != False + + # Construct a model instance of LanguageDetectionResult by calling from_dict on the json representation + language_detection_result_model_dict = LanguageDetectionResult.from_dict(language_detection_result_model_json).__dict__ + language_detection_result_model2 = LanguageDetectionResult(**language_detection_result_model_dict) + + # Verify the model instances are equivalent + assert language_detection_result_model == language_detection_result_model2 + + # Convert model instance back to dict and verify no loss of data + language_detection_result_model_json2 = language_detection_result_model.to_dict() + assert language_detection_result_model_json2 == language_detection_result_model_json + + +class TestModel_LanguageDetectionResults: + """ + Test Class for LanguageDetectionResults + """ + + def test_language_detection_results_serialization(self): + """ + Test serialization/deserialization for LanguageDetectionResults + """ + + # Construct dict forms of any model objects needed in order to build this model. + + language_info_model = {} # LanguageInfo + language_info_model['confidence'] = 36.0 + language_info_model['language'] = 'testString' + language_info_model['timestamp'] = 36.0 + + language_detection_result_model = {} # LanguageDetectionResult + language_detection_result_model['language_info'] = [language_info_model] + + # Construct a json representation of a LanguageDetectionResults model + language_detection_results_model_json = {} + language_detection_results_model_json['results'] = [language_detection_result_model] + language_detection_results_model_json['result_index'] = 38 + + # Construct a model instance of LanguageDetectionResults by calling from_dict on the json representation + language_detection_results_model = LanguageDetectionResults.from_dict(language_detection_results_model_json) + assert language_detection_results_model != False + + # Construct a model instance of LanguageDetectionResults by calling from_dict on the json representation + language_detection_results_model_dict = LanguageDetectionResults.from_dict(language_detection_results_model_json).__dict__ + language_detection_results_model2 = LanguageDetectionResults(**language_detection_results_model_dict) + + # Verify the model instances are equivalent + assert language_detection_results_model == language_detection_results_model2 + + # Convert model instance back to dict and verify no loss of data + language_detection_results_model_json2 = language_detection_results_model.to_dict() + assert language_detection_results_model_json2 == language_detection_results_model_json + + +class TestModel_LanguageInfo: + """ + Test Class for LanguageInfo + """ + + def test_language_info_serialization(self): + """ + Test serialization/deserialization for LanguageInfo + """ + + # Construct a json representation of a LanguageInfo model + language_info_model_json = {} + language_info_model_json['confidence'] = 36.0 + language_info_model_json['language'] = 'testString' + language_info_model_json['timestamp'] = 36.0 + + # Construct a model instance of LanguageInfo by calling from_dict on the json representation + language_info_model = LanguageInfo.from_dict(language_info_model_json) + assert language_info_model != False + + # Construct a model instance of LanguageInfo by calling from_dict on the json representation + language_info_model_dict = LanguageInfo.from_dict(language_info_model_json).__dict__ + language_info_model2 = LanguageInfo(**language_info_model_dict) + + # Verify the model instances are equivalent + assert language_info_model == language_info_model2 + + # Convert model instance back to dict and verify no loss of data + language_info_model_json2 = language_info_model.to_dict() + assert language_info_model_json2 == language_info_model_json + + class TestModel_LanguageModel: """ Test Class for LanguageModel @@ -4911,6 +5285,18 @@ def test_recognition_job_serialization(self): audio_metrics_model['sampling_interval'] = 36.0 audio_metrics_model['accumulated'] = audio_metrics_details_model + enriched_results_transcript_timestamp_model = {} # EnrichedResultsTranscriptTimestamp + enriched_results_transcript_timestamp_model['from'] = 36.0 + enriched_results_transcript_timestamp_model['to'] = 36.0 + + enriched_results_transcript_model = {} # EnrichedResultsTranscript + enriched_results_transcript_model['text'] = 'testString' + enriched_results_transcript_model['timestamp'] = enriched_results_transcript_timestamp_model + + enriched_results_model = {} # EnrichedResults + enriched_results_model['transcript'] = enriched_results_transcript_model + enriched_results_model['status'] = 'testString' + speech_recognition_results_model = {} # SpeechRecognitionResults speech_recognition_results_model['results'] = [speech_recognition_result_model] speech_recognition_results_model['result_index'] = 38 @@ -4918,6 +5304,7 @@ def test_recognition_job_serialization(self): speech_recognition_results_model['processing_metrics'] = processing_metrics_model speech_recognition_results_model['audio_metrics'] = audio_metrics_model speech_recognition_results_model['warnings'] = ['testString'] + speech_recognition_results_model['enriched_results'] = enriched_results_model # Construct a json representation of a RecognitionJob model recognition_job_model_json = {} @@ -5024,6 +5411,18 @@ def test_recognition_jobs_serialization(self): audio_metrics_model['sampling_interval'] = 36.0 audio_metrics_model['accumulated'] = audio_metrics_details_model + enriched_results_transcript_timestamp_model = {} # EnrichedResultsTranscriptTimestamp + enriched_results_transcript_timestamp_model['from'] = 36.0 + enriched_results_transcript_timestamp_model['to'] = 36.0 + + enriched_results_transcript_model = {} # EnrichedResultsTranscript + enriched_results_transcript_model['text'] = 'testString' + enriched_results_transcript_model['timestamp'] = enriched_results_transcript_timestamp_model + + enriched_results_model = {} # EnrichedResults + enriched_results_model['transcript'] = enriched_results_transcript_model + enriched_results_model['status'] = 'testString' + speech_recognition_results_model = {} # SpeechRecognitionResults speech_recognition_results_model['results'] = [speech_recognition_result_model] speech_recognition_results_model['result_index'] = 38 @@ -5031,6 +5430,7 @@ def test_recognition_jobs_serialization(self): speech_recognition_results_model['processing_metrics'] = processing_metrics_model speech_recognition_results_model['audio_metrics'] = audio_metrics_model speech_recognition_results_model['warnings'] = ['testString'] + speech_recognition_results_model['enriched_results'] = enriched_results_model recognition_job_model = {} # RecognitionJob recognition_job_model['id'] = 'testString' @@ -5384,6 +5784,18 @@ def test_speech_recognition_results_serialization(self): audio_metrics_model['sampling_interval'] = 36.0 audio_metrics_model['accumulated'] = audio_metrics_details_model + enriched_results_transcript_timestamp_model = {} # EnrichedResultsTranscriptTimestamp + enriched_results_transcript_timestamp_model['from'] = 36.0 + enriched_results_transcript_timestamp_model['to'] = 36.0 + + enriched_results_transcript_model = {} # EnrichedResultsTranscript + enriched_results_transcript_model['text'] = 'testString' + enriched_results_transcript_model['timestamp'] = enriched_results_transcript_timestamp_model + + enriched_results_model = {} # EnrichedResults + enriched_results_model['transcript'] = enriched_results_transcript_model + enriched_results_model['status'] = 'testString' + # Construct a json representation of a SpeechRecognitionResults model speech_recognition_results_model_json = {} speech_recognition_results_model_json['results'] = [speech_recognition_result_model] @@ -5392,6 +5804,7 @@ def test_speech_recognition_results_serialization(self): speech_recognition_results_model_json['processing_metrics'] = processing_metrics_model speech_recognition_results_model_json['audio_metrics'] = audio_metrics_model speech_recognition_results_model_json['warnings'] = ['testString'] + speech_recognition_results_model_json['enriched_results'] = enriched_results_model # Construct a model instance of SpeechRecognitionResults by calling from_dict on the json representation speech_recognition_results_model = SpeechRecognitionResults.from_dict(speech_recognition_results_model_json)