feat: OpenAITTS

This commit is contained in:
TomTom101
2024-06-01 10:13:28 +02:00
parent ae049961b7
commit 8683cae719
3 changed files with 61 additions and 35 deletions

39
tests/test_openai_tts.py Normal file
View File

@@ -0,0 +1,39 @@
import asyncio
import unittest
import openai
import pyaudio
from dotenv import load_dotenv
from pipecat.frames.frames import AudioRawFrame, ErrorFrame
from pipecat.services.openai import OpenAITTSService
load_dotenv()
class TestWhisperOpenAIService(unittest.IsolatedAsyncioTestCase):
async def test_whisper_tts(self):
pa = pyaudio.PyAudio()
stream = pa.open(format=pyaudio.paInt16,
channels=1,
rate=24_000,
output=True)
tts = OpenAITTSService(voice="nova")
async for frame in tts.run_tts("Hello, there. Nice to meet you, seems to work well"):
self.assertIsInstance(frame, AudioRawFrame)
stream.write(frame.audio)
await asyncio.sleep(.5)
stream.stop_stream()
pa.terminate()
tts = OpenAITTSService(voice="invalid_voice")
with self.assertRaises(openai.BadRequestError):
async for frame in tts.run_tts("wont work"):
self.assertIsInstance(frame, ErrorFrame)
if __name__ == "__main__":
unittest.main()

View File

@@ -1,14 +0,0 @@
import unittest
from pipecat.services.openai import WhisperTTSService
class TestWhisperOpenAIService(unittest.IsolatedAsyncioTestCase):
async def test_whisper_tts(self):
tts = WhisperTTSService()
# tts_response = await tts.run_tts("Hello, world")
await tts.say("Hi! If you want to talk to me, just say 'Hey Robot'.")
if __name__ == "__main__":
unittest.main()