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

refactor(): refactor cartesia tts #444

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 5 additions & 5 deletions agents/examples/experimental/property.json
Original file line number Diff line number Diff line change
Expand Up @@ -3009,7 +3009,7 @@
"api_key": "${env:DEEPGRAM_API_KEY}",
"language": "en-US",
"model": "nova-2",
"sample_rate": "16000"
"sample_rate": 16000
}
},
{
Expand All @@ -3036,10 +3036,10 @@
"name": "cartesia_tts",
"property": {
"api_key": "${env:CARTESIA_API_KEY}",
"cartesia_version": "2024-06-10",
"language": "en",
"model_id": "sonic-english",
"voice_id": "f9836c6e-a0bd-460e-9d3c-f7299fa60f94",
"sample_rate": "16000"
"sample_rate": 16000,
"voice_id": "f9836c6e-a0bd-460e-9d3c-f7299fa60f94"
}
},
{
Expand Down Expand Up @@ -3253,7 +3253,7 @@
"api_key": "${env:DEEPGRAM_API_KEY}",
"language": "en-US",
"model": "nova-2",
"sample_rate": "16000"
"sample_rate": 16000
}
},
{
Expand Down
19 changes: 19 additions & 0 deletions agents/ten_packages/extension/cartesia_tts/BUILD.gn
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",
]
}
29 changes: 29 additions & 0 deletions agents/ten_packages/extension/cartesia_tts/README.md
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 -->
12 changes: 6 additions & 6 deletions agents/ten_packages/extension/cartesia_tts/__init__.py
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
19 changes: 19 additions & 0 deletions agents/ten_packages/extension/cartesia_tts/addon.py
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 agents/ten_packages/extension/cartesia_tts/cartesia_tts.py
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 agents/ten_packages/extension/cartesia_tts/cartesia_tts_addon.py

This file was deleted.

197 changes: 0 additions & 197 deletions agents/ten_packages/extension/cartesia_tts/cartesia_tts_extension.py

This file was deleted.

Loading