Skip to content
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

Feat 4155 text to speech python #171

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
cfccf90
Implement Text To Speech base
rubynguyen1510 Jul 21, 2023
252f56c
added unit test aws
rubynguyen1510 Jul 27, 2023
46c425e
Fixed test main
Jul 28, 2023
0f809f5
Merge branch 'TextToSpeech' into noah
Mushmou Jul 28, 2023
fb4f90e
Fixed test main (#10)
Mushmou Jul 28, 2023
d3e31aa
New main.py (#11)
rubynguyen1510 Jul 28, 2023
67439e9
Fixed merge conflict test main
Jul 28, 2023
0af9143
Concluded merge
Jul 28, 2023
21aae45
Working version of Text To Speech
Jul 28, 2023
e6d2c71
Noah (#12)
Mushmou Jul 28, 2023
de769bf
Merging because I need to Merge branch 'TextToSpeech' of https://gith…
Jul 28, 2023
edc867e
Deleted aws sandbox dir
Jul 28, 2023
d049c3c
made a working version of google test and fixed run commands in req.txt
Jul 31, 2023
b082a75
added unit tests for AWS and validate_common
rubynguyen1510 Jul 31, 2023
abb1034
added unit tests for AWS and validate_common (#13)
rubynguyen1510 Jul 31, 2023
ac3ab30
Working version of azure and google, made change to readme, removed a…
Jul 31, 2023
19626f4
Merged latest changes
Jul 31, 2023
3b913c7
Noah (#14)
Mushmou Jul 31, 2023
be11445
Merge branch 'TextToSpeech' of https://github.com/Mushmou/examples in…
Jul 31, 2023
79487b3
Resolvved merge conflicts
rubynguyen1510 Jul 31, 2023
33d4e13
removed test file and added ok check for main.py
Jul 31, 2023
81b5dc8
working version of main.py and updated a test in testmain for aws
Jul 31, 2023
c22005c
Noah (#15)
Mushmou Jul 31, 2023
3967cd0
All three services working in main.py and fixed key error in test main
Aug 1, 2023
4f0d448
Merge branch 'TextToSpeech' into noah
Mushmou Aug 1, 2023
7130c03
Noah (#16)
Mushmou Aug 1, 2023
fcf680e
Finished test in unittest
Aug 1, 2023
9a1743d
fixed a small space
Aug 1, 2023
5b54ba0
Merge branch 'noah' of https://github.com/Mushmou/examples into noah
Aug 1, 2023
65d7699
Noah (#17)
Mushmou Aug 1, 2023
31b56da
Ngoc (#18)
rubynguyen1510 Aug 1, 2023
d312b50
finished test main
Aug 1, 2023
4bae639
Linted main.py
Aug 1, 2023
d31818f
Noah (#19)
Mushmou Aug 1, 2023
2f6fab7
Fixed azure bug
Mushmou Aug 1, 2023
5040d45
Merge remote-tracking branch 'refs/remotes/origin/TextToSpeech' into …
rubynguyen1510 Aug 1, 2023
680cb22
Changes after code review
rubynguyen1510 Aug 2, 2023
3839334
merge noah
Aug 2, 2023
9611d1a
added the changes from PR #20
Aug 2, 2023
06e6e54
Added note in testmain (#23)
Mushmou Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 0 additions & 154 deletions python/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions python/text-to-speech/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
85 changes: 85 additions & 0 deletions python/text-to-speech/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# 🗣️ Text To Speech with Google, Azure and AWS API

A Python cloud function for text to speech synthesis using [Google](https://cloud.google.com/text-to-speech), [Azure](https://azure.microsoft.com/en-us/products/ai-services/text-to-speech) and [AWS](https://docs.aws.amazon.com/polly/latest/dg/API_SynthesizeSpeech.html).

### Supported Providers and Language Codes
| Providers | Language Code (BCP-47) |
| ----------- | ----------- |
| Google |[Google Language Code](https://cloud.google.com/text-to-speech/docs/voices) |
| Azure |[Azure Language Code](https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=stt) |
| AWS |[AWS Language Code](https://docs.aws.amazon.com/polly/latest/dg/API_SynthesizeSpeech.html) |

### Example Input:
```json
{
"provider":"<YOUR_PROVIDER_HERE>",
"language":"<YOUR_LANGUAGE_CODE>",
"text":"Hello world!"
}
```
### Example output:
```json
{
"success":true,
"audio_bytes":"iVBORw0KGgoAAAANSUhE...o6Ie+UAAAAASU5CYII="
}
```
### Example error output:
```json
{
"success":false,
"error":"Missing API_KEY""
}
```

## 📝 Environment Variables
List of environment variables used by this cloud function:
- **API_KEY** - Supported with Google, Azure, and AWS.
- **PROJECT_ID** - Supported with Google.
- **SECRET_API_KEY** - Supported with AWS.

| **Google**| **AWS** | **Azure** |
| -------- | -------- | -------- |
|API_KEY | API_KEY | API_KEY
|PROJECT_ID |SECRET_API_KEY|


## 🚀 Deployment

1. Clone this repository, and enter this function folder:

```bash
git clone https://github.com/open-runtimes/examples.git && cd examples
cd python/text-to-speech
```

2. Enter this function folder and build the code:
```bash
docker run --rm --interactive --tty --volume $PWD:/usr/code openruntimes/python:v2-3.10 sh /usr/local/src/build.sh
```
As a result, a `code.tar.gz` file will be generated.

3. Start the Open Runtime:
```bash
docker run -p 3000:3000 -e INTERNAL_RUNTIME_KEY=secret-key -e INTERNAL_RUNTIME_ENTRYPOINT=main.py --rm --interactive --tty --volume $PWD/code.tar.gz:/tmp/code.tar.gz:ro openruntimes/python:v2-3.10 sh /usr/local/src/start.sh
```

> Make sure to replace `YOUR_API_KEY` with your key.
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/openruntimes/python:v2-3.10).

4. Run the cURL function to send request.
>Google Curl Example (Supports only API_KEY and PROJECT_ID in Environment Variables)
```bash
curl http://localhost:3000/ -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json" -d '{"payload": {"provider": "google", "language": "en-US", "text": "Hello World!"}, "variables": {"API_KEY": "<YOUR_API_KEY>", "PROJECT_ID": "<YOUR_PROJECT_ID>"}}'
```
>Azure Curl Example (Supports API_KEY in Environment Variables)
```bash
curl http://localhost:3000/ -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json" -d '{"payload": {"provider": "azure", "language":"en-US", "text": "Hello World!"}, "variables": {"API_KEY": "<YOUR_API_KEY>"}}'
```
>AWS Curl Example (Supports API_KEY and SECRET_API_KEY in Environment Variables)
```bash
curl http://localhost:3000/ -H "X-Internal-Challenge: secret-key" -H "Content-Type: application/json" -d '{"payload": {"provider": "aws", "language":"en-US", "text":"Hello World!"}, "variables": {"API_KEY": "<YOUR_API_KEY>", "SECRET_API_KEY": "<YOUR_SECRET_API_KEY>"}}'
```
## 📝 Notes
- This function is designed for use with Appwrite Cloud Functions. You can learn more about it in [Appwrite docs](https://appwrite.io/docs/functions).
- This example is compatible with Python 3.10. Other versions may work but are not guaranteed to work as they haven't been tested.
Loading