added app message

This commit is contained in:
Chad Bailey
2024-03-18 19:52:31 +00:00
parent 2f4e31d1b2
commit 6d3c52ae81

View File

@@ -26,7 +26,8 @@ logger.setLevel(logging.DEBUG)
"""
This example looks a bit different than the chatbot example, because it isn't waiting on the user to stop talking to start translating.
It also isn't saving what the user or bot says into the context object for use in subsequent interactions.
It also isn't saving what the user or bot says into the context object for use in subsequent interactions. This example also sends
the translated text back to the transport as an App Message, so clients can show subtitles.
"""
@@ -50,6 +51,20 @@ class TranslationProcessor(FrameProcessor):
yield frame
class TranslationSubtitles(FrameProcessor):
def __init__(self, language):
self._language = language
async def process_frame(self, frame: Frame) -> AsyncGenerator[Frame, None]:
if isinstance(frame, TextFrame):
app_message = {
"language": self._language,
"text": frame.text
}
else:
yield frame
async def main(room_url: str, token):
async with aiohttp.ClientSession() as session:
transport = DailyTransportService(
@@ -73,7 +88,8 @@ async def main(room_url: str, token):
model="gpt-4-turbo-preview")
sa = SentenceAggregator()
tp = TranslationProcessor("Spanish")
pipeline = Pipeline([sa, tp, llm, tts])
ts = TranslationSubtitles("Spanish")
pipeline = Pipeline([sa, tp, llm, tts, ts])
transport.transcription_settings["extra"]["endpointing"] = True
transport.transcription_settings["extra"]["punctuate"] = True