mirror of
https://github.com/run-llama/openai_realtime_client.git
synced 2026-07-01 21:04:00 -04:00
fix text input
This commit is contained in:
@@ -2,14 +2,22 @@
|
||||
|
||||
## Installation
|
||||
|
||||
Install all dependendencies:
|
||||
Install system deps:
|
||||
|
||||
```bash
|
||||
brew install ffmpeg
|
||||
```
|
||||
|
||||
Install python deps:
|
||||
|
||||
```bash
|
||||
pip install pyaudio pynput pydub websockets
|
||||
pip install -U openai pyaudio pynput pydub websockets
|
||||
```
|
||||
|
||||
Set your openai key:
|
||||
|
||||
```bash
|
||||
export OPENAI_API_KEY="sk-..."
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
@@ -175,7 +175,6 @@ class InputHandler:
|
||||
self.command_queue.put_nowait, ('enter', self.text_input)
|
||||
)
|
||||
self.text_input = ""
|
||||
print("\nYou: ", end="", flush=True)
|
||||
elif key == keyboard.KeyCode.from_char('r'):
|
||||
self.loop.call_soon_threadsafe(
|
||||
self.command_queue.put_nowait, ('r', None)
|
||||
@@ -187,10 +186,8 @@ class InputHandler:
|
||||
elif hasattr(key, 'char'):
|
||||
if key == keyboard.Key.backspace:
|
||||
self.text_input = self.text_input[:-1]
|
||||
print('\b \b', end="", flush=True)
|
||||
else:
|
||||
self.text_input += key.char
|
||||
print(key.char, end="", flush=True)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
@@ -224,8 +221,8 @@ async def main():
|
||||
print("- Press 'r' to start recording audio")
|
||||
print("- Press 'space' to stop recording")
|
||||
print("- Press 'q' to quit")
|
||||
print("\nYou: ", end="", flush=True)
|
||||
|
||||
print("")
|
||||
|
||||
while True:
|
||||
# Wait for commands from the input handler
|
||||
command, data = await input_handler.command_queue.get()
|
||||
@@ -247,7 +244,8 @@ async def main():
|
||||
elif command == 'enter' and data:
|
||||
# Send text message
|
||||
await client.send_text(data)
|
||||
|
||||
|
||||
await asyncio.sleep(0.01)
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user