-
Notifications
You must be signed in to change notification settings - Fork 1
Text to speech #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text to speech #20
Conversation
Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local>
* finalized main.py --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local>
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local>
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req * removed test file and added ok check for main.py * working version of main.py and updated a test in testmain for aws --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local>
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req * removed test file and added ok check for main.py * working version of main.py and updated a test in testmain for aws * All three services working in main.py and fixed key error in test main * Finished test in unittest * fixed a small space --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local> Co-authored-by: Noah Jacinto <noahjacinto@Noahs-Air.fios-router.home>
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req * removed test file and added ok check for main.py * working version of main.py and updated a test in testmain for aws * All three services working in main.py and fixed key error in test main * Finished test in unittest * fixed a small space * finished test main --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local> Co-authored-by: Noah Jacinto <noahjacinto@Noahs-Air.fios-router.home>
|
|
||
| Your function is now listening on port `3000`, and you can execute it by sending `POST` request with appropriate authorization headers. To learn more about runtime, you can visit Python runtime [README](https://github.com/open-runtimes/open-runtimes/tree/main/runtimes/python-3.10). | ||
|
|
||
| ## 📝 Notes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming the README is still a TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we are working on this.
| def test_speech_invalid_credential(self) -> None: | ||
| """Test credentials for speech method.""" | ||
| instance = self.get_azure_instance("WRONG_API_KEY", "WRONG_PROJECT_ID") | ||
| # Mock the requests.post method used in get_token. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try to avoid the temptation to write comments which says the same thing as the code.
Comments are great for explaining why you are doing something or for explaining complicated code. For simple code, though, don't add comments which just repeat the code.
python/text-to-speech/test_main.py
Outdated
| def get_req(self, payload: str, variables: str, provider: str, text: str, | ||
| language: str) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| def get_req(self, payload: str, variables: str, provider: str, text: str, | |
| language: str) -> None: | |
| def get_req( | |
| self, | |
| payload: str, | |
| variables: str, | |
| provider: str, | |
| text: str, | |
| language: str, | |
| ) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you using all of these arguments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we did use all the args in the parameter.
python/.gitignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you intend to remove this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes we intend to remove .gitignore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot remove it now because every time we run the code, py_cache is generated. When we are done with testing and preparing to make a pull request, we can remove the .gitignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It looks like you removed the repo-wide
python/.gitignorefile and added a custompython/text-to-speech/,gitignorefile. You probably should not remove the former. Edits to that file should be out of scope for this PR. - You should be able to
git commitwithout using the--allflag and specifying which files are or are not included in a commit.
python/text-to-speech/main.py
Outdated
| """ | ||
| # Endpoint for cognitive services speech api | ||
| url = ( | ||
| f"https://{Azure.REGION}.tts." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| f"https://{Azure.REGION}.tts." | |
| f"https://{self.REGION}.tts." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain the difference between the two?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say someone decided to implement an AzureAsia class ... which is exactly like Azure except it uses a different region.
class AzureAsia(Azure):
REGION = "asia"If you read the region from self.REGION then the AzureAsia class will read the correct region. However, if you're reading the Azure.REGION then the updated REGION value will be ignored.
python/text-to-speech/test_main.py
Outdated
| # Raise Exception. | ||
| mock_synthesize_speech.side_effect = Exception | ||
| # Assert the raise. | ||
| self.assertRaises(Exception, instance.speech, "hello", "en-EN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the instance.speech call be inside the mock context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt notice we can remove the instance.speech, I thought we had to keep the function and its params but I removed it. The change only includes the patch with raise exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update we changed the code again.
def test_speech_invalid_language(self) -> None:
"""Test language for speech method."""
# Set up mock.
instance = self.get_google_instance("123", "123")
with mock.patch.object(
texttospeech.TextToSpeechClient, "synthesize_speech"
) as mock_synthesize_speech:
# Raise Exception.
mock_synthesize_speech.side_effect = Exception
# Assert the raise.
self.assertRaises(Exception, instance.speech, "hello", "en-EN")How does this look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better :) This code calls speech() with a mocked client, which I believe was the intent.
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req * removed test file and added ok check for main.py * working version of main.py and updated a test in testmain for aws * All three services working in main.py and fixed key error in test main * Finished test in unittest * fixed a small space * finished test main --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local> Co-authored-by: Noah Jacinto <noahjacinto@Noahs-Air.fios-router.home>
* Fixed test main * Working version of Text To Speech * Deleted aws sandbox dir * made a working version of google test and fixed run commands in req.txt * Working version of azure and google, made change to readme, removed azure from req * removed test file and added ok check for main.py * working version of main.py and updated a test in testmain for aws * All three services working in main.py and fixed key error in test main * Finished test in unittest * fixed a small space * finished test main * added the changes from PR #20 --------- Co-authored-by: Noah Jacinto <noahjacinto@Noahs-MacBook-Air.local> Co-authored-by: Noah Jacinto <noahjacinto@Noahs-Air.fios-router.home>
python/.gitignore
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- It looks like you removed the repo-wide
python/.gitignorefile and added a custompython/text-to-speech/,gitignorefile. You probably should not remove the former. Edits to that file should be out of scope for this PR. - You should be able to
git commitwithout using the--allflag and specifying which files are or are not included in a commit.
python/text-to-speech/test_main.py
Outdated
| # Raise Exception. | ||
| mock_client.side_effect = Exception | ||
| # Assert the raise. | ||
| self.assertRaises(Exception, instance.speech, None, "en-US") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this call the speech() function with a mocked or real client?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we were supposed to put the assert raise with the with block, so it can be part of the mocked client.
python/text-to-speech/main.py
Outdated
| """ | ||
| # Endpoint for cognitive services speech api | ||
| url = ( | ||
| f"https://{Azure.REGION}.tts." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Say someone decided to implement an AzureAsia class ... which is exactly like Azure except it uses a different region.
class AzureAsia(Azure):
REGION = "asia"If you read the region from self.REGION then the AzureAsia class will read the correct region. However, if you're reading the Azure.REGION then the updated REGION value will be ignored.
python/text-to-speech/test_main.py
Outdated
| # Raise Exception. | ||
| mock_synthesize_speech.side_effect = Exception | ||
| # Assert the raise. | ||
| self.assertRaises(Exception, instance.speech, "hello", "en-EN") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better :) This code calls speech() with a mocked client, which I believe was the intent.
python/.gitignore
Outdated
| # and can be added to the global gitignore or merged into this file. For a more nuclear | ||
| # option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
| #.idea/ | ||
| #.idea/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not be changing as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our plan is to add the changes to a new branch called feat 4122 text to speech branch, it would fix this I assume.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we create the feat-4155 with only one commit, we will double-check to ensure that changes in this file do not appear.
python/text-to-speech/README.md
Outdated
| ```json | ||
| { | ||
| "success":false, | ||
| "error":"Missing API_KEY"" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub highlighting is telling me this is invalid JSON
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay we fixed the extra quote on README.md
python/text-to-speech/main.py
Outdated
| polly_client = boto3.Session( | ||
| aws_access_key_id=self.api_key, | ||
| aws_secret_access_key=self.secret_api_key, | ||
| region_name=self.REGION).client("polly") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| region_name=self.REGION).client("polly") | |
| region_name=self.REGION, | |
| ).client("polly") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fixed this one.
python/text-to-speech/main.py
Outdated
| provider_class = Google(req) | ||
| elif provider == "azure": | ||
| provider_class = Azure(req) | ||
| else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you want to check the provider string here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already check if the provider is in the list of Supported_providers in the validate_common function (line 241 - 243).
python/text-to-speech/test_main.py
Outdated
| def __init__( | ||
| self, | ||
| data: dict[dict[str, str, str], dict[str, str]], | ||
| ) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ) -> None: | |
| ) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay we fixed this one.
No description provided.