Repository navigation
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
executable file
·328 lines (258 loc) · 9.96 KB
/
Copy pathdocker-entrypoint.sh
File metadata and controls
executable file
·328 lines (258 loc) · 9.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#!/bin/bash
set -e
### Compose compatibility
# docker-compose.yml sets LVA_COMPOSE_VERSION in the environment of the service. Increase it here and in
# docker-compose.yml / docker-compose.dev.yml together whenever the Compose file changes in a way that an image depends on.
# Version 1: docker-compose.yml up to 1.1.18 (no LVA_COMPOSE_VERSION, downloaded wake words in the volume at /app/local).
# Version 2: downloaded wake words in the volume at /app/wakewords/downloaded, Sendspin control directory mounted.
COMPOSE_VERSION_OLDEST=1
COMPOSE_VERSION_CURRENT=2
COMPOSE_VERSION=${LVA_COMPOSE_VERSION:-1}
COMPOSE_FILE_URL="https://github.com/OHF-Voice/linux-voice-assistant/blob/main/docker-compose.yml"
if ! [[ "$COMPOSE_VERSION" =~ ^[0-9]+$ ]]; then
echo "❌ LVA_COMPOSE_VERSION=\"$COMPOSE_VERSION\" is not a number. It is set by docker-compose.yml, do not set it in .env."
exit 1
fi
if [ "$COMPOSE_VERSION" -gt "$COMPOSE_VERSION_CURRENT" ]; then
echo "❌ This docker-compose.yml (compose version $COMPOSE_VERSION) needs a newer image." \
"This image supports compose versions $COMPOSE_VERSION_OLDEST to $COMPOSE_VERSION_CURRENT." \
"Pull the image again or set LVA_IMAGE_TAG in .env to a newer release."
exit 1
fi
if [ "$COMPOSE_VERSION" -lt "$COMPOSE_VERSION_OLDEST" ]; then
echo "❌ This docker-compose.yml (compose version $COMPOSE_VERSION) is too old for this image." \
"This image supports compose versions $COMPOSE_VERSION_OLDEST to $COMPOSE_VERSION_CURRENT." \
"Replace it with the current one: $COMPOSE_FILE_URL"
exit 1
fi
echo "Compose version: $COMPOSE_VERSION (this image supports $COMPOSE_VERSION_OLDEST to $COMPOSE_VERSION_CURRENT)"
if [ "$COMPOSE_VERSION" -lt "$COMPOSE_VERSION_CURRENT" ]; then
echo "⚠️ docker-compose.yml is outdated (compose version $COMPOSE_VERSION, current $COMPOSE_VERSION_CURRENT)." \
"LVA still starts, but replace it with the current one: $COMPOSE_FILE_URL"
fi
# Compose version 1 keeps downloaded wake words in the volume at /app/local and does not give the user access to
# /app/wakewords/downloaded. LVA then gets its own wake word root under /tmp, whose "downloaded" points to that volume.
if [ "$COMPOSE_VERSION" = "1" ] && [ -z "${WAKE_WORD_ROOT_DIR}" ] && [ ! -w /app/wakewords/downloaded ] && [ -d /app/local ] && [ -w /app/local ]; then
LEGACY_WAKE_WORD_ROOT=/tmp/lva-wakewords
mkdir -p "$LEGACY_WAKE_WORD_ROOT" /app/local/microwakeword
ln -sfn /app/wakewords/internal "$LEGACY_WAKE_WORD_ROOT/internal"
ln -sfn /app/local "$LEGACY_WAKE_WORD_ROOT/downloaded"
ln -sfn /app/wakewords/custom "$LEGACY_WAKE_WORD_ROOT/custom"
# Up to 1.1.18 downloaded wake words were stored in /app/local/external_wake_words. They are copied, not moved,
# so that an older image still finds them.
copied=0
shopt -s nullglob
for file in /app/local/external_wake_words/*.json /app/local/external_wake_words/*.tflite; do
if [ ! -e "/app/local/microwakeword/$(basename "$file")" ]; then
cp "$file" /app/local/microwakeword/
copied=$((copied + 1))
fi
done
shopt -u nullglob
WAKE_WORD_ROOT_DIR=$LEGACY_WAKE_WORD_ROOT
echo "⚠️ Wake word layout of compose version 1: downloaded wake words are kept in /app/local/microwakeword" \
"(copied $copied files from /app/local/external_wake_words)."
fi
### Handlers
# Handle parameters
EXTRA_ARGS=()
if [ "$ENABLE_DEBUG" = "1" ]; then
EXTRA_ARGS+=( "--debug" )
fi
if [ "$ENABLE_COLORED_DEBUG" = "1" ]; then
EXTRA_ARGS+=( "--colored-debug" )
fi
if [ -n "${CLIENT_NAME}" ]; then
EXTRA_ARGS+=( "--name" "$CLIENT_NAME" )
fi
PREFERENCES_FILE=${PREFERENCES_FILE:-"/app/configuration/preferences.json"}
if [ -n "${PREFERENCES_FILE}" ]; then
EXTRA_ARGS+=( "--preferences-file" "$PREFERENCES_FILE" )
fi
if [ -n "${NETWORK_INTERFACE}" ]; then
EXTRA_ARGS+=( "--network-interface" "$NETWORK_INTERFACE" )
fi
if [ -n "${MAC_ADDRESS}" ]; then
EXTRA_ARGS+=( "--mac-address" "$MAC_ADDRESS" )
fi
# IP-ADDRESS
if [ -n "${HOST}" ]; then
EXTRA_ARGS+=( "--host" "$HOST" )
fi
PORT=${PORT:-6053}
if [ -n "${PORT}" ]; then
EXTRA_ARGS+=( "--port" "$PORT" )
fi
if [ "$ENABLE_ENCRYPTION" = "1" ]; then
EXTRA_ARGS+=( "--enable-encryption" )
fi
if [ -n "${ENCRYPTION_KEY_FILE}" ]; then
EXTRA_ARGS+=( "--encryption-key-file" "$ENCRYPTION_KEY_FILE" )
fi
if [ -n "${AUDIO_INPUT_DEVICE}" ]; then
EXTRA_ARGS+=( "--audio-input-device" "$AUDIO_INPUT_DEVICE" )
fi
if [ -n "${AUDIO_INPUT_BLOCK_SIZE}" ]; then
EXTRA_ARGS+=( "--audio-input-block-size" "$AUDIO_INPUT_BLOCK_SIZE" )
fi
if [ -n "${AUDIO_OUTPUT_DEVICE}" ]; then
EXTRA_ARGS+=( "--audio-output-device" "$AUDIO_OUTPUT_DEVICE" )
fi
if [ -n "${MUSIC_OUTPUT_DEVICE}" ]; then
EXTRA_ARGS+=( "--music-output-device" "$MUSIC_OUTPUT_DEVICE" )
fi
if [ -n "${MPV_PLAYER_DUCK_MODE}" ]; then
EXTRA_ARGS+=( "--mpv-player-duck-mode" "$MPV_PLAYER_DUCK_MODE" )
fi
if [ -n "${ENABLE_SENDSPIN_BRIDGE}" ]; then
EXTRA_ARGS+=( "--enable-sendspin-bridge" "$ENABLE_SENDSPIN_BRIDGE" )
fi
if [ -n "${SENDSPIN_CONTROL_DIR}" ]; then
EXTRA_ARGS+=( "--sendspin-control-dir" "$SENDSPIN_CONTROL_DIR" )
fi
if [ -n "${SENDSPIN_PLAYER_DUCK_MODE}" ]; then
EXTRA_ARGS+=( "--sendspin-player-duck-mode" "$SENDSPIN_PLAYER_DUCK_MODE" )
fi
if [ -n "${MIC_VOLUME}" ]; then
EXTRA_ARGS+=( "--mic-volume" "$MIC_VOLUME" )
fi
if [ -n "${MIC_AUTO_GAIN}" ]; then
EXTRA_ARGS+=( "--mic-auto-gain" "$MIC_AUTO_GAIN" )
fi
if [ -n "${MIC_NOISE_SUPPRESSION}" ]; then
EXTRA_ARGS+=( "--mic-noise-suppression" "$MIC_NOISE_SUPPRESSION" )
fi
if [ -n "${AUDIO_INPUT_CHANNELS}" ]; then
EXTRA_ARGS+=( "--audio-input-channels" "$AUDIO_INPUT_CHANNELS" )
fi
if [ "$ENABLE_THINKING_SOUND" = "1" ]; then
EXTRA_ARGS+=( "--enable-thinking-sound" )
fi
if [ -n "${ENABLE_CONTINUE_CONVERSATION_SOUND}" ]; then
EXTRA_ARGS+=( "--enable-continue-conversation-sound" "$ENABLE_CONTINUE_CONVERSATION_SOUND" )
fi
if [ "$LISTEN_DURING_WAKE_SOUND" = "1" ]; then
EXTRA_ARGS+=( "--listen-during-wake-sound" )
fi
if [ -n "${WAKE_WORD_ROOT_DIR}" ]; then
EXTRA_ARGS+=( "--wake-word-root-dir" "$WAKE_WORD_ROOT_DIR" )
fi
if [ -n "${WAKE_WORD_DIR}" ]; then
EXTRA_ARGS+=( "--wake-word-dir" "$WAKE_WORD_DIR" )
fi
if [ -n "${WAKE_MODEL}" ]; then
EXTRA_ARGS+=( "--wake-model" "$WAKE_MODEL" )
fi
if [ -n "${WAKE_MODEL_2}" ]; then
EXTRA_ARGS+=( "--wake-model-2" "$WAKE_MODEL_2" )
fi
if [ -n "${STOP_MODEL}" ]; then
EXTRA_ARGS+=( "--stop-model" "$STOP_MODEL" )
fi
if [ -n "${REFACTORY_SECONDS}" ]; then
EXTRA_ARGS+=( "--refractory-seconds" "$REFACTORY_SECONDS" )
fi
if [ -n "${CONTINUE_CONVERSATION_DELAY}" ]; then
EXTRA_ARGS+=( "--continue-conversation-delay" "$CONTINUE_CONVERSATION_DELAY" )
fi
if [ -n "${WAKEUP_SOUND}" ]; then
EXTRA_ARGS+=( "--wakeup-sound" "$WAKEUP_SOUND" )
fi
if [ -n "${START_LISTENING_SOUND}" ]; then
EXTRA_ARGS+=( "--start-listening-sound" "$START_LISTENING_SOUND" )
fi
if [ -n "${TIMER_FINISHED_SOUND}" ]; then
EXTRA_ARGS+=( "--timer-finished-sound" "$TIMER_FINISHED_SOUND" )
fi
if [ -n "${PROCESSING_SOUND}" ]; then
EXTRA_ARGS+=( "--processing-sound" "$PROCESSING_SOUND" )
fi
if [ -n "${MUTE_SOUND}" ]; then
EXTRA_ARGS+=( "--mute-sound" "$MUTE_SOUND" )
fi
if [ -n "${UNMUTE_SOUND}" ]; then
EXTRA_ARGS+=( "--unmute-sound" "$UNMUTE_SOUND" )
fi
if [ -n "${PIPELINE_ENDED_SOUND}" ]; then
EXTRA_ARGS+=( "--pipeline-ended-sound" "$PIPELINE_ENDED_SOUND" )
fi
if [ -n "${BUTTON_DOUBLE_PRESS_SOUND}" ]; then
EXTRA_ARGS+=( "--button-double-press-sound" "$BUTTON_DOUBLE_PRESS_SOUND" )
fi
if [ -n "${BUTTON_TRIPLE_PRESS_SOUND}" ]; then
EXTRA_ARGS+=( "--button-triple-press-sound" "$BUTTON_TRIPLE_PRESS_SOUND" )
fi
if [ -n "${BUTTON_LONG_PRESS_SOUND}" ]; then
EXTRA_ARGS+=( "--button-long-press-sound" "$BUTTON_LONG_PRESS_SOUND" )
fi
if [ -n "${CONTINUE_CONVERSATION_SOUND}" ]; then
EXTRA_ARGS+=( "--continue-conversation-sound" "$CONTINUE_CONVERSATION_SOUND" )
fi
if [ -n "${TIMER_MAX_RING_SECONDS}" ]; then
EXTRA_ARGS+=( "--timer-max-ring-seconds" "$TIMER_MAX_RING_SECONDS" )
fi
if [ -n "${PERIPHERAL_HOST}" ]; then
EXTRA_ARGS+=( "--peripheral-host" "$PERIPHERAL_HOST" )
fi
if [ -n "${PERIPHERAL_PORT}" ]; then
EXTRA_ARGS+=( "--peripheral-port" "$PERIPHERAL_PORT" )
fi
if [ -n "${PERIPHERAL_VOLUME_STEP}" ]; then
EXTRA_ARGS+=( "--peripheral-volume-step" "$PERIPHERAL_VOLUME_STEP" )
fi
if [ -n "${PERIPHERAL_STARTUP_WAIT}" ]; then
EXTRA_ARGS+=( "--peripheral-startup-wait" "$PERIPHERAL_STARTUP_WAIT" )
fi
if [ -n "${ENABLE_REMOTE_UNMUTE}" ]; then
EXTRA_ARGS+=( "--enable-remote-unmute" "$ENABLE_REMOTE_UNMUTE" )
fi
if [ -n "${ENABLE_ZEROCONF}" ]; then
EXTRA_ARGS+=( "--enable-zeroconf" "$ENABLE_ZEROCONF" )
fi
if [ "$DISABLE_PERIPHERAL_API" = "1" ]; then
EXTRA_ARGS+=( "--disable-peripheral-api" )
fi
if [ "$ENABLE_OUTPUT_ONLY" = "1" ]; then
EXTRA_ARGS+=( "--output-only" )
fi
# Add cookie file for pulseaudio to prevent errors
PULSE_COOKIE=${PULSE_COOKIE:-"/run/user/1000/pulse/cookie"}
if [[ "$PULSE_COOKIE" != "DISABLED" ]]; then
if [ ! -f "$PULSE_COOKIE" ]; then
echo "Creating PulseAudio cookie file at $PULSE_COOKIE"
touch "$PULSE_COOKIE"
chmod 600 "$PULSE_COOKIE"
fi
fi
### Wait for PulseAudio
# Skip wait if SKIP_PULSE_AUDIO_WAIT is set (for local development)
if [ "$SKIP_PULSE_AUDIO_WAIT" != "1" ]; then
CP_MAX_RETRIES=30
CP_RETRY_DELAY=1
### while maybe besser?
echo "Checking PulseAudio service status..."
for i in $(seq 1 $CP_MAX_RETRIES); do
# Check if PulseAudio is running
if pactl info >/dev/null 2>&1; then
echo "✅ PulseAudio is running"
break
fi
if [ $i -eq $CP_MAX_RETRIES ]; then
echo "❌ PulseAudio did not start after $CP_MAX_RETRIES seconds"
exit 2
fi
echo "⏳ PulseAudio not running yet, retrying in $CP_RETRY_DELAY s..."
sleep $CP_RETRY_DELAY
done
fi
### Start application
if [ "$LIST_DEVICES" = "1" ]; then
echo "list input devices"
./script/run "$@" "${EXTRA_ARGS[@]}" --list-input-devices
echo "list output devices"
./script/run "$@" "${EXTRA_ARGS[@]}" --list-output-devices
echo "wait 20s and then starting the application"
sleep 20
fi
echo "starting application"
exec ./script/run "$@" "${EXTRA_ARGS[@]}"