Skip to content

Commit

Permalink
update deepgram tts to new service structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Moishe committed Feb 14, 2024
1 parent 53e97bd commit 92ec564
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
36 changes: 36 additions & 0 deletions src/dailyai/services/deepgram_ai_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import os
import aiohttp
import requests

from dailyai.services.ai_services import TTSService


class DeepgramAIService(TTSService):
def __init__(
self,
*,
aiohttp_session: aiohttp.ClientSession,
api_key,
voice,
sample_rate=16000
):
super().__init__()

self._api_key = api_key
self._voice = voice
self._sample_rate = sample_rate
self._aiohttp_session = aiohttp_session

async def run_tts(self, sentence):
self.logger.info(f"Running deepgram tts for {sentence}")
base_url = "https://api.beta.deepgram.com/v1/speak"
request_url = f"{base_url}?model={self._voice}&encoding=linear16&container=none&sample_rate={self._sample_rate}"
headers = {"authorization": f"token {self._api_key}", "Content-Type": "application/json"}
data = {"text": sentence}

async with self._aiohttp_session.post(
request_url, headers=headers, json=data
) as r:
async for chunk in r.content:
if chunk:
yield chunk
29 changes: 0 additions & 29 deletions src/dailyai/services/to_be_updated/deepgram_ai_service.py

This file was deleted.

0 comments on commit 92ec564

Please sign in to comment.