diff --git a/edenai_apis/apis/faker/__init__.py b/edenai_apis/apis/faker/__init__.py new file mode 100644 index 00000000..957c8573 --- /dev/null +++ b/edenai_apis/apis/faker/__init__.py @@ -0,0 +1 @@ +from .faker_api import FakerApi diff --git a/edenai_apis/apis/faker/faker_api.py b/edenai_apis/apis/faker/faker_api.py new file mode 100644 index 00000000..c9777950 --- /dev/null +++ b/edenai_apis/apis/faker/faker_api.py @@ -0,0 +1,71 @@ +""" + Fake provider class used for tests +""" +from io import BufferedReader +from random import randint +from time import sleep +from typing import Dict, List, Optional + +from edenai_apis.features import AudioInterface, ProviderInterface +from edenai_apis.features.audio import SpeechToTextAsyncDataClass, SpeechDiarization +from edenai_apis.utils.types import ( + AsyncBaseResponseType, + AsyncLaunchJobResponseType, + AsyncPendingResponseType, + AsyncResponseType, +) + +class FakerApi(ProviderInterface, AudioInterface): + provider_name = "faker" + + def __init__(self, api_keys: Dict = {}) -> None: + super().__init__() + + def audio__speech_to_text_async__launch_job( + self, + file: str, + language: str, + speakers: int, + profanity_filter: bool, + vocabulary: list, + audio_attributes: tuple, + file_url: str = "", + provider_params: dict = dict(), + ) -> AsyncLaunchJobResponseType: + sleep(randint(1, 3)) + return AsyncLaunchJobResponseType(provider_job_id="SomeFakeID") + + def audio__speech_to_text_async__get_job_result( + self, provider_job_id: str + ) -> AsyncBaseResponseType[SpeechToTextAsyncDataClass]: + sleep(randint(1, 3)) + + standardized_response = SpeechToTextAsyncDataClass( + text="empty", + diarization=SpeechDiarization( + total_speakers = 1 + ) + ) + provider_correct_response = AsyncResponseType[SpeechToTextAsyncDataClass]( + original_response={}, + standardized_response=standardized_response, + provider_job_id=provider_job_id, + ) + + chance_to_stop = randint(2, 1000) + + if provider_job_id == 'FINISHED': + return provider_correct_response + if provider_job_id == 'ERROR': + raise Exception("error") + if provider_job_id == "pending": + return AsyncPendingResponseType[SpeechToTextAsyncDataClass]( + provider_job_id=provider_job_id + ) + if chance_to_stop < 250: + return provider_correct_response + if chance_to_stop > 994: + raise Exception("error") + return AsyncPendingResponseType[SpeechToTextAsyncDataClass]( + provider_job_id=provider_job_id + ) diff --git a/edenai_apis/apis/faker/info.json b/edenai_apis/apis/faker/info.json new file mode 100644 index 00000000..0c49c4d2 --- /dev/null +++ b/edenai_apis/apis/faker/info.json @@ -0,0 +1,53 @@ +{ + "audio": { + "speech_to_text_async": { + "constraints": { + "languages": [ + "ar", + "bg", + "ca", + "hr", + "cs", + "da", + "nl", + "en", + "fa", + "fi", + "fr", + "de", + "el", + "he", + "hi", + "hu", + "id", + "it", + "ja", + "ko", + "lv", + "lt", + "ms", + "cmn", + "no", + "pl", + "pt", + "ro", + "ru", + "sk", + "sl", + "es", + "sv", + "ta", + "te", + "tr" + ], + "file_extensions": [ + "flac", + "wav", + "mp3" + ], + "allow_null_language": true + }, + "version": "v1" + } + } +} diff --git a/edenai_apis/apis/faker/outputs/audio/speech_to_text_async_output.json b/edenai_apis/apis/faker/outputs/audio/speech_to_text_async_output.json new file mode 100644 index 00000000..7c68e0fb --- /dev/null +++ b/edenai_apis/apis/faker/outputs/audio/speech_to_text_async_output.json @@ -0,0 +1,13 @@ +{ + "status": "succeeded", + "provider_job_id": "SomeFakeID", + "original_response": {}, + "standardized_response": { + "text": "empty", + "diarization": { + "total_speakers": 1, + "entries": [], + "error_message": null + } + } +} \ No newline at end of file