-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(): refactor cartesia tts (#444)
- Loading branch information
1 parent
f996515
commit 616c55b
Showing
15 changed files
with
355 additions
and
492 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
import("//build/feature/ten_package.gni") | ||
|
||
ten_package("cartesia_tts") { | ||
package_kind = "extension" | ||
|
||
resources = [ | ||
"__init__.py", | ||
"addon.py", | ||
"extension.py", | ||
"manifest.json", | ||
"property.json", | ||
"tests", | ||
] | ||
} |
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,29 @@ | ||
# cartesia_tts | ||
|
||
<!-- brief introduction for the extension --> | ||
|
||
## Features | ||
|
||
<!-- main features introduction --> | ||
|
||
- xxx feature | ||
|
||
## API | ||
|
||
Refer to `api` definition in [manifest.json] and default values in [property.json](property.json). | ||
|
||
<!-- Additional API.md can be referred to if extra introduction needed --> | ||
|
||
## Development | ||
|
||
### Build | ||
|
||
<!-- build dependencies and steps --> | ||
|
||
### Unit test | ||
|
||
<!-- how to do unit test for the extension --> | ||
|
||
## Misc | ||
|
||
<!-- others if applicable --> |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from . import cartesia_tts_addon | ||
from .extension import EXTENSION_NAME | ||
from .log import logger | ||
|
||
|
||
logger.info(f"{EXTENSION_NAME} extension loaded") | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from . import addon |
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 @@ | ||
# | ||
# This file is part of TEN Framework, an open source project. | ||
# Licensed under the Apache License, Version 2.0. | ||
# See the LICENSE file for more information. | ||
# | ||
from ten import ( | ||
Addon, | ||
register_addon_as_extension, | ||
TenEnv, | ||
) | ||
|
||
|
||
@register_addon_as_extension("cartesia_tts") | ||
class CartesiaTTSExtensionAddon(Addon): | ||
|
||
def on_create_instance(self, ten_env: TenEnv, name: str, context) -> None: | ||
from .extension import CartesiaTTSExtension | ||
ten_env.log_info("CartesiaTTSExtensionAddon on_create_instance") | ||
ten_env.on_create_instance_done(CartesiaTTSExtension(name), context) |
42 changes: 42 additions & 0 deletions
42
agents/ten_packages/extension/cartesia_tts/cartesia_tts.py
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,42 @@ | ||
# | ||
# | ||
# Agora Real Time Engagement | ||
# Created by XinHui Li in 2024. | ||
# Copyright (c) 2024 Agora IO. All rights reserved. | ||
# | ||
# | ||
|
||
from dataclasses import dataclass | ||
from typing import AsyncIterator | ||
from cartesia import AsyncCartesia | ||
|
||
from ten_ai_base.config import BaseConfig | ||
|
||
|
||
@dataclass | ||
class CartesiaTTSConfig(BaseConfig): | ||
api_key: str = "" | ||
language: str = "en" | ||
model_id: str = "sonic-english" | ||
request_timeout_seconds: int = 10 | ||
sample_rate: int = 16000 | ||
voice_id: str = "f9836c6e-a0bd-460e-9d3c-f7299fa60f94" | ||
|
||
class CartesiaTTS: | ||
def __init__(self, config: CartesiaTTSConfig) -> None: | ||
self.config = config | ||
self.client = AsyncCartesia(api_key=config.api_key, timeout=config.request_timeout_seconds) | ||
|
||
def text_to_speech_stream(self, text: str) -> AsyncIterator[bytes]: | ||
return self.client.tts.sse( | ||
language=self.config.language, | ||
model_id=self.config.model_id, | ||
output_format={ | ||
"container": "raw", | ||
"encoding": "pcm_s16le", | ||
"sample_rate": self.config.sample_rate, | ||
}, | ||
stream=True, | ||
transcript=text, | ||
voice_id=self.config.voice_id, | ||
) |
24 changes: 0 additions & 24 deletions
24
agents/ten_packages/extension/cartesia_tts/cartesia_tts_addon.py
This file was deleted.
Oops, something went wrong.
197 changes: 0 additions & 197 deletions
197
agents/ten_packages/extension/cartesia_tts/cartesia_tts_extension.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.