Skip to main content

No project description provided

Project description

DeepGrain.AI - TTS Service Client

Install

pip install deep-tts

Server

import os

from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.responses import StreamingResponse

from deep_tts import DeepTTS
from deep_tts.data_models import UserInput

load_dotenv(".env")

app = FastAPI()


@app.post("/raw_text")
def text_to_speech(user_text: UserInput = UserInput(text="你好吗?")):
    # get user text, send to openai to get stream
    text = user_text.model_dump().get("text")
    tts_client = DeepTTS(os.getenv("ACCESS_TOKEN"), "openai-tts1")

    # get text stream
    text_stream = tts_client.openai_text_stream(text)

    # init tts server connection
    conn_response = tts_client.init_conn()
    task_id = conn_response.headers["task_id"]

    # send text stream to tts server
    response = tts_client.send_text_stream(text_stream, task_id)
    print("\n\n", response.headers)

    return StreamingResponse(
        conn_response.iter_content(chunk_size=64),
        media_type="audio/wav",
    )


if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=8182)

Client

import json
import threading
from datetime import datetime

import requests

from deep_tts.common import save_audio_stream_to_file


def single_request():
    "get openai text stream and send it to server to get audio chunks, and save the audio files to cache folder."
    url = "http://127.0.0.1:8182/raw_text"

    payload = json.dumps({"text": "你好吗?"})
    headers = {"accept": "application/json", "Content-Type": "application/json"}

    response = requests.request("POST", url, headers=headers, data=payload)

    save_audio_stream_to_file(response, "cache_folder")


single_request()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deep_tts-0.1.19.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

deep_tts-0.1.19-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file deep_tts-0.1.19.tar.gz.

File metadata

  • Download URL: deep_tts-0.1.19.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.13 Darwin/23.4.0

File hashes

Hashes for deep_tts-0.1.19.tar.gz
Algorithm Hash digest
SHA256 926e8d8daf647735711b451e9fffefd6f88fcbfe8a880655c5b84317fa4ce18b
MD5 aa05c21a45a089c6dd27db9960621c43
BLAKE2b-256 c7a20b172fbef9b4c2ccdc0866bd8db4da10aa35140e1bd2a8868bf8f37ba31f

See more details on using hashes here.

File details

Details for the file deep_tts-0.1.19-py3-none-any.whl.

File metadata

  • Download URL: deep_tts-0.1.19-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.10.13 Darwin/23.4.0

File hashes

Hashes for deep_tts-0.1.19-py3-none-any.whl
Algorithm Hash digest
SHA256 fe1c104643fb7d6c1001cdb70361f3c4263fb51ac5a4aab5b76c6ce3a04018bb
MD5 407f07ceeece26080bdadfca00f47f0a
BLAKE2b-256 3e4224811b42f07d92d731c534eb6fcd91bce9fdcccab458f809dacdcd49cd63

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page