-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] add faker provider for tests
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .faker_api import FakerApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
edenai_apis/apis/faker/outputs/audio/speech_to_text_async_output.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"status": "succeeded", | ||
"provider_job_id": "SomeFakeID", | ||
"original_response": {}, | ||
"standardized_response": { | ||
"text": "empty", | ||
"diarization": { | ||
"total_speakers": 1, | ||
"entries": [], | ||
"error_message": null | ||
} | ||
} | ||
} |