Audio Agent
AudioAgent
Bases: Agent
Handles audio recording, playback, and speech-to-text transcription.
This module uses OpenAI's API to transcribe audio input and synthesize speech. Set Environment Variable NO_AUDIO=1 to disable audio recording and playback. It will then take input from the terminal.
Usage:
audio_agent = AudioAgent(api_key="your-openai-api-key", use_pyaudio=False)
audio_agent.speak("How can I help you?")
message = audio_agent.listen()
Source code in mbodied/agents/sense/audio/audio_agent.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
__init__(listen_filename='tmp_listen.wav', tmp_speak_filename='tmp_speak.mp3', use_pyaudio=True, api_key=None, run_local=False)
Initializes the AudioAgent with specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
listen_filename
|
str
|
The filename for storing recorded audio. |
'tmp_listen.wav'
|
tmp_speak_filename
|
str
|
The filename for storing synthesized speech. |
'tmp_speak.mp3'
|
use_pyaudio
|
bool
|
Whether to use PyAudio for playback. Prefer setting to False for Mac. |
True
|
api_key
|
str
|
The API key for OpenAI. |
None
|
run_local
|
bool
|
Whether to run the whisper model locally instead of using OpenAI. |
False
|
Source code in mbodied/agents/sense/audio/audio_agent.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
|
listen(keep_audio=False, mode='speak')
Listens for audio input and transcribes it using OpenAI's API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
keep_audio
|
bool
|
Whether to keep the recorded audio file. |
False
|
mode
|
str
|
The mode of input (speak, type, speak_or_type). |
'speak'
|
Returns:
Type | Description |
---|---|
str
|
The transcribed text from the audio input. |
Source code in mbodied/agents/sense/audio/audio_agent.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
play_audio(filename)
Plays an audio file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
filename
|
str
|
The filename of the audio file to play. |
required |
Source code in mbodied/agents/sense/audio/audio_agent.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
|
record_audio()
Records audio from the microphone and saves it to a file.
Source code in mbodied/agents/sense/audio/audio_agent.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
speak(message, voice='onyx', api_key=None)
Synthesizes speech from text using OpenAI's API and plays it back.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message
|
str
|
The text message to synthesize. |
required |
voice
|
str
|
The voice model to use for synthesis. |
'onyx'
|
api_key
|
str
|
The API key for OpenAI. |
None
|
Source code in mbodied/agents/sense/audio/audio_agent.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
|