-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathedge.py
More file actions
72 lines (59 loc) · 1.98 KB
/
Copy pathedge.py
File metadata and controls
72 lines (59 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from os import path
from typing import TYPE_CHECKING
from edge_tts import Communicate
from api.enums import TtsProvider
from api.interface import EdgeTtsConfig, SoundConfig
from providers.interfaces import TtsInterface, tts_provider
from services.audio_player import AudioPlayer
from services.file import get_writable_dir
from services.printr import Printr
if TYPE_CHECKING:
from api.interface import WingmanConfig
RECORDING_PATH = "audio_output"
OUTPUT_FILE: str = "edge_tts.mp3"
printr = Printr()
class Edge:
def __init__(self):
self.random_voices = {}
async def play_audio(
self,
text: str,
config: EdgeTtsConfig,
sound_config: SoundConfig,
audio_player: AudioPlayer,
wingman_name: str,
):
communicate, output_file = await self.__generate_speech(
text=text, voice=config.voice
)
audio, sample_rate = audio_player.get_audio_from_file(output_file)
await audio_player.play_with_effects(
input_data=(audio, sample_rate),
config=sound_config,
wingman_name=wingman_name,
)
async def __generate_speech(
self,
text: str,
voice: str = "en-US-GuyNeural",
rate: str = "+0%",
):
if not text:
return
communicate = Communicate(text=text, voice=voice, rate=rate)
file_path = path.join(get_writable_dir(RECORDING_PATH), OUTPUT_FILE)
await communicate.save(file_path)
return communicate, file_path
@tts_provider(TtsProvider.EDGE_TTS)
class EdgeTts(TtsInterface):
def __init__(self, config: "WingmanConfig"):
self._edge = Edge()
self._config = config
async def play_audio(self, text, sound_config, audio_player, wingman_name):
await self._edge.play_audio(
text=text,
config=self._config.edge_tts,
sound_config=sound_config,
audio_player=audio_player,
wingman_name=wingman_name,
)