-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1397 from arc53/tts
Add endpoint for Text-To-Speech conversion
- Loading branch information
Showing
4 changed files
with
55 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
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 |
---|---|---|
|
@@ -85,3 +85,4 @@ vine==5.1.0 | |
wcwidth==0.2.13 | ||
werkzeug==3.0.4 | ||
yarl==1.11.1 | ||
gTTS==2.3.2 |
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,10 @@ | ||
from abc import ABC, abstractmethod | ||
|
||
|
||
class BaseTTS(ABC): | ||
def __init__(self): | ||
pass | ||
|
||
@abstractmethod | ||
def text_to_speech(self, *args, **kwargs): | ||
pass |
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,19 @@ | ||
import io | ||
import base64 | ||
from gtts import gTTS | ||
from application.tts.base import BaseTTS | ||
|
||
|
||
class GoogleTTS(BaseTTS): | ||
def __init__(self, text): | ||
self.text = text | ||
|
||
|
||
def text_to_speech(self): | ||
lang = "en" | ||
audio_fp = io.BytesIO() | ||
tts = gTTS(text=self.text, lang=lang, slow=False) | ||
tts.write_to_fp(audio_fp) | ||
audio_fp.seek(0) | ||
audio_base64 = base64.b64encode(audio_fp.read()).decode("utf-8") | ||
return audio_base64, lang |