Merge pull request #28 from daily-co/update-playht-service
Update playht service
This commit is contained in:
@@ -1,36 +1,40 @@
|
|||||||
import io
|
import io
|
||||||
import os
|
|
||||||
import struct
|
import struct
|
||||||
from pyht import Client
|
from pyht import Client
|
||||||
from dotenv import load_dotenv
|
|
||||||
from pyht.client import TTSOptions
|
from pyht.client import TTSOptions
|
||||||
from pyht.protos.api_pb2 import Format
|
from pyht.protos.api_pb2 import Format
|
||||||
|
|
||||||
from services.ai_service import AIService
|
from dailyai.services.ai_services import TTSService
|
||||||
|
|
||||||
|
|
||||||
class PlayHTAIService(AIService):
|
class PlayHTAIService(TTSService):
|
||||||
def __init__(self, **kwargs):
|
|
||||||
super().__init__(**kwargs)
|
|
||||||
|
|
||||||
self.speech_key = os.getenv("PLAY_HT_KEY") or ''
|
def __init__(
|
||||||
self.user_id = os.getenv("PLAY_HT_USER_ID") or ''
|
self,
|
||||||
|
*,
|
||||||
|
api_key,
|
||||||
|
user_id,
|
||||||
|
voice_url
|
||||||
|
):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self.speech_key = api_key
|
||||||
|
self.user_id = user_id
|
||||||
|
|
||||||
self.client = Client(
|
self.client = Client(
|
||||||
user_id=self.user_id,
|
user_id=self.user_id,
|
||||||
api_key=self.speech_key,
|
api_key=self.speech_key,
|
||||||
)
|
)
|
||||||
self.options = TTSOptions(
|
self.options = TTSOptions(
|
||||||
voice="s3://voice-cloning-zero-shot/820da3d2-3a3b-42e7-844d-e68db835a206/sarah/manifest.json",
|
voice=voice_url,
|
||||||
sample_rate=16000,
|
sample_rate=16000,
|
||||||
quality="higher",
|
quality="higher",
|
||||||
format=Format.FORMAT_WAV)
|
format=Format.FORMAT_WAV)
|
||||||
|
|
||||||
def close(self):
|
def __del__(self):
|
||||||
super().close()
|
|
||||||
self.client.close()
|
self.client.close()
|
||||||
|
|
||||||
def run_tts(self, sentence):
|
async def run_tts(self, sentence):
|
||||||
b = bytearray()
|
b = bytearray()
|
||||||
in_header = True
|
in_header = True
|
||||||
for chunk in self.client.tts(sentence, self.options):
|
for chunk in self.client.tts(sentence, self.options):
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import os
|
|||||||
|
|
||||||
from dailyai.services.daily_transport_service import DailyTransportService
|
from dailyai.services.daily_transport_service import DailyTransportService
|
||||||
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
from dailyai.services.elevenlabs_ai_service import ElevenLabsTTSService
|
||||||
|
from dailyai.services.playht_ai_service import PlayHTAIService
|
||||||
|
|
||||||
from examples.foundational.support.runner import configure
|
from examples.foundational.support.runner import configure
|
||||||
|
|
||||||
@@ -26,14 +27,23 @@ async def main(room_url):
|
|||||||
meeting_duration_minutes,
|
meeting_duration_minutes,
|
||||||
mic_enabled=True
|
mic_enabled=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
"""
|
||||||
tts = ElevenLabsTTSService(
|
tts = ElevenLabsTTSService(
|
||||||
aiohttp_session=session,
|
aiohttp_session=session,
|
||||||
api_key=os.getenv("ELEVENLABS_API_KEY"),
|
api_key=os.getenv("ELEVENLABS_API_KEY"),
|
||||||
voice_id=os.getenv("ELEVENLABS_VOICE_ID"))
|
voice_id=os.getenv("ELEVENLABS_VOICE_ID"))
|
||||||
|
"""
|
||||||
|
tts = PlayHTAIService(
|
||||||
|
api_key=os.getenv("PLAY_HT_API_KEY"),
|
||||||
|
user_id=os.getenv("PLAY_HT_USER_ID"),
|
||||||
|
voice_url=os.getenv("PLAY_HT_VOICE_URL"),
|
||||||
|
)
|
||||||
|
|
||||||
# Register an event handler so we can play the audio when the participant joins.
|
# Register an event handler so we can play the audio when the participant joins.
|
||||||
@transport.event_handler("on_participant_joined")
|
@transport.event_handler("on_participant_joined")
|
||||||
async def on_participant_joined(transport, participant):
|
async def on_participant_joined(transport, participant):
|
||||||
|
nonlocal tts
|
||||||
if participant["info"]["isLocal"]:
|
if participant["info"]["isLocal"]:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -46,6 +56,7 @@ async def main(room_url):
|
|||||||
await transport.stop_when_done()
|
await transport.stop_when_done()
|
||||||
|
|
||||||
await transport.run()
|
await transport.run()
|
||||||
|
del(tts)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user