| 133 | # This example uses the SDK's stream_input.connect() method to |
| 134 | # connect to the /v0/tts/stream/input endpoint. |
| 135 | async def example3(): |
| 136 | assert api_key, "HUME_API_KEY or TEST_HUME_API_KEY not found in environment variables." |
| 137 | async with hume.tts.stream_input.connect(version="1", no_binary=True, strip_headers=True) as stream: |
| 138 | |
| 139 | async def send_input(): |
| 140 | print("Sending TTS messages...") |
| 141 | await stream.send_publish( |
| 142 | PublishTts( |
| 143 | text="Hello", |
| 144 | voice=PostedUtteranceVoiceWithName(name="Ava Song", provider="HUME_AI"), |
| 145 | ) |
| 146 | ) |
| 147 | await stream.send_publish(PublishTts(text=" world.")) |
| 148 | # The whitespace ^ is important |
| 149 | # Otherwise the model would see "Helloworld." and not "Hello world." |
| 150 | await stream.send_publish(PublishTts(flush=True)) |
| 151 | print("Waiting 8 seconds...") |
| 152 | await asyncio.sleep(8) |
| 153 | await stream.send_publish(PublishTts(text="Goodbye, world.")) |
| 154 | await stream.send_publish(PublishTts(flush=True)) |
| 155 | print("Closing stream...") |
| 156 | await stream.send_publish(PublishTts(close=True)) |
| 157 | |
| 158 | async def handle_messages(): |
| 159 | await play_audio_streaming(base64.b64decode(chunk.audio) async for chunk in stream) |
| 160 | |
| 161 | await asyncio.gather(handle_messages(), send_input()) |
| 162 | |
| 163 | |
| 164 | async def main(): |