Skip to content

Commit

Permalink
Noah (#12)
Browse files Browse the repository at this point in the history
* Fixed test main

* Working version of Text To Speech

---------

Co-authored-by: Noah Jacinto <[email protected]>
  • Loading branch information
Mushmou and Noah Jacinto authored Jul 28, 2023
1 parent d3e31aa commit e6d2c71
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 62 deletions.
5 changes: 2 additions & 3 deletions python/text-to-speech/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def speech(self, text: str, language: str) -> bytes:


class Azure(TextToSpeech):
"""This class represents the implementation of Azure text to speech.""
"""This class represents the implementation of Azure text to speech."""
def validate_request(self, req: requests) -> None:
"""
This method validates the request data for Azure text to speech.
Expand Down Expand Up @@ -178,8 +178,7 @@ def speech(self, text: str, language: str) -> bytes:
list_of_providers = ["google", "azure", "aws"]


def validate_common(req: requests) -> tuple[str]:
def validate_common(req: requests) -> tuple:
"""
This function validates the common fields in the request data
that are independent of the text-to-speech provider.
Expand Down
61 changes: 2 additions & 59 deletions python/text-to-speech/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
from parameterized import parameterized
from google.cloud import texttospeech


# Local imports
import main
import secret

RESULT_GOOGLE = (
pathlib.Path("python/text-to-speech/results/google.txt").
Expand All @@ -24,7 +22,6 @@
read_text(encoding="utf-8"))



def get_instance(provider, key, project_id):
IMPLEMENTATIONS = {
"google": main.Google,
Expand Down Expand Up @@ -144,60 +141,6 @@ def test_speech_key_exception(self, text, language):
pass


class AWSTest(unittest.TestCase):
"""AWS API Test Cases"""
def test_validate_request(self, req):
"""Test validate_request method when all required fields are present."""
pass

def test_validate_request_missing_aws_access_key_id(self, req):
"""Test validate_request method when 'AWS_ACCESS_KEY_ID' is missing."""
pass

def test_validate_request_missing_aws_secret_access_key(self, req):
"""Test validate_request method when 'AWS_SECRET_ACCESS_KEY' is missing."""
pass

def test_speech(self, text, language):
"""Test speech method for text-to-speech synthesis."""
pass

def test_speech_key_exception(self, text, language):
"""Test speech method for handling exceptions during text-to-speech synthesis."""
pass


class ValidateCommonTest(unittest.TestCase):
"""Test Cases for validate_common function"""
def test_validate_common(self, req):
"""Test validate_common function with valid input."""
pass

def test_missing_text(self, req):
"""Test validate_common function when 'text' is missing."""
pass

def test_missing_language(self, req):
"""Test validate_common function when 'language' is missing."""
pass

def test_validate_request_missing_aws_access_key_id(self, req):
"""Test validate_request methsod when 'AWS_ACCESS_KEY_ID' is missing."""
pass

def test_validate_request_missing_aws_secret_access_key(self, req):
"""Test validate_request method when 'AWS_SECRET_ACCESS_KEY' is missing."""
pass

def test_speech(self, text, language):
"""Test speech method for text-to-speech synthesis."""
pass

def test_speech_key_exception(self, text, language):
"""Test speech method for handling exceptions during text-to-speech synthesis."""
pass


class AWSTest(unittest.TestCase):
"""AWS API Test Cases"""
def test_validate_request(self, req):
Expand Down Expand Up @@ -233,7 +176,7 @@ def test_speech(self):
# Set up mock
with patch.object(texttospeech, "TextToSpeechClient") as mock_client:
mock_response = mock_client.return_value
mock_response.synthesize_speech.return_value.audio_content = base64.b64decode(RESULT_AWS)
mock_response.synthesize_speech.return_value.audio_content = base64.b64decode("RESULT_AWS")

# Call the speech method
audio_stream = aws_instance.speech(text, language)
Expand All @@ -245,7 +188,7 @@ def test_speech(self):
mock_response.synthesize_speech.assert_called_once_with(VoiceId="Joanna", OutputFormat="mp3", Text=text, LanguageCode=language)

# Assert the result
self.assertEqual(audio_stream, base64.b64decode(RESULT_AWS))
self.assertEqual(audio_stream, base64.b64decode("RESULT_AWS"))

def test_speech_key_exception(self, text, language):
"""Test speech method for handling exceptions during text-to-speech synthesis."""
Expand Down

0 comments on commit e6d2c71

Please sign in to comment.