Skip to content

Commit 44e9b8b

Browse files
authored
feat: add OpenVINO AI Plugins (#50)
1 parent 68fefcc commit 44e9b8b

File tree

3 files changed

+472
-1
lines changed

3 files changed

+472
-1
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,59 @@ distributions.</p>
2323

2424
<p align="center">Published for <img src="https://raw.githubusercontent.com/anythingcodes/slack-emoji-for-techies/gh-pages/emoji/tux.png" align="top" width="24" /> with :gift_heart: by Snapcrafters</p>
2525

26+
## OpenVINO™ AI Plugins
27+
28+
This snap contains support for AI features including:
29+
30+
- Music Separation
31+
- Noise Suppression
32+
- Music Generation and Continuation
33+
- Transcription
34+
- Super Resolution
35+
36+
The plugins come installed out-of-the-box and support running on Intel hardware only (CPU, GPU, and NPU). Instructions for using each of the features can be found in the [upstream GitHub repository](https://github.com/intel/openvino-plugins-ai-audacity/tree/main/doc/feature_doc).
37+
38+
> [!IMPORTANT]
39+
> The models (which are roughly 6.2 GiB in size total) are NOT built into the snap. To use the AI features you must download and install them from the command line. Note that downloading the models may take several minutes or longer, depending on the speed of your internet connection. Please be patient!
40+
41+
To ease the process of downloading and installing the models, an interactive command is available within the snap that can be invoked like so:
42+
43+
```shell
44+
sudo audacity.fetch-models
45+
```
46+
47+
This will provide you with an interactive menu where you can select the model you wish to download and install. Alternatively, if you wish to enable all of the AI features, you can simply pass the `--batch` flag:
48+
49+
```shell
50+
sudo audacity.fetch-models --batch
51+
```
52+
53+
54+
> [!IMPORTANT]
55+
> Please ensure you are in the `render` Unix group on your system in order to access Intel accelerators for the plugins (Intel GPU and NPU).
56+
To check your current groups, please run the following from a terminal:
57+
58+
```shell
59+
groups
60+
```
61+
62+
If you do not see `render` listed in the output, you may add your current user with the following:
63+
64+
```shell
65+
sudo usermod -a -G render $USER
66+
```
67+
68+
Now log out and back in to ensure your active session has the `render` group included.
69+
70+
To ensure the device nodes have appropriate group permissions set, you may also run:
71+
72+
```shell
73+
sudo chown root:render /dev/accel/accel*
74+
sudo chmod g+rw /dev/accel/accel*
75+
sudo chown root:render /dev/dri/render*
76+
sudo chmod g+rw /dev/dri/render*
77+
```
78+
2679
## How to contribute to this snap
2780

2881
Thanks for your interest! Below you find instructions to help you contribute to this snap.

bin/fetch-models

Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
#!/bin/bash
2+
3+
set -e
4+
set -E # ensure ERR trap is inherited by shell functions
5+
set -o pipefail
6+
7+
SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
8+
9+
MODELS="${SNAP_DATA}/models/openvino-models"
10+
MUSICGEN_TMP="${SNAP_DATA}/tmp/musicgen_tmp"
11+
MUSICGEN="${MODELS}/musicgen"
12+
WHISPER_TMP="${SNAP_DATA}/tmp/whisper_tmp"
13+
WHISPER="${MODELS}"
14+
SEPARATION_TMP="${SNAP_DATA}/tmp/separation_tmp"
15+
SEPARATION="${MODELS}"
16+
SUPPRESSION_TMP="${SNAP_DATA}/tmp/suppression_tmp"
17+
SUPPRESSION="${MODELS}"
18+
RESOLUTION_TMP="${SNAP_DATA}/tmp/resolution_tmp"
19+
RESOLUTION="${MODELS}/audiosr"
20+
21+
usage() {
22+
cat<< EOF
23+
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-b]
24+
25+
Manage the installation of OpenVINO™ AI models for Audacity.
26+
27+
This command must be run with sudo as it installs models to ${SNAP_DATA}, where write access
28+
is only permitted for the root user.
29+
30+
Available options:
31+
32+
-h, --help Print this help and exit
33+
-v, --verbose Print script debug info
34+
-b, --batch Install all models in non-interactive mode
35+
EOF
36+
exit
37+
}
38+
39+
cleanup() {
40+
RC=$?
41+
rm -rf "${MUSICGEN_TMP}" "${WHISPER_TMP}" "${SEPARATION_TMP}" "${SUPPRESSION_TMP}" "${RESOLUTION_TMP}"
42+
if [ "${RC}" -ne 0 ]; then
43+
echo "Warning: the script is not exiting normally. You may need to run again. Pass the -v flag to show debug info."
44+
fi
45+
exit "${RC}"
46+
}
47+
48+
trap cleanup SIGINT SIGTERM ERR
49+
50+
silent() {
51+
if [ "${verbose}" = 'no' ]; then
52+
"$@" > /dev/null 2>&1
53+
else
54+
"$@"
55+
fi
56+
}
57+
58+
musicgen_status() {
59+
if [ -d "${MUSICGEN}" ] && \
60+
[ "$(find "${MUSICGEN}" -maxdepth 1 -type f | wc -l)" = '12' ] && \
61+
[ "$(find "${MUSICGEN}/mono" -maxdepth 1 -type f | wc -l)" = '17' ] && \
62+
[ "$(find "${MUSICGEN}/stereo" -maxdepth 1 -type f | wc -l)" = '17' ]; then
63+
echo ' (installed) '
64+
fi
65+
echo ''
66+
}
67+
68+
whisper_status() {
69+
if [ -d "${WHISPER}" ] && \
70+
[ "$(find "${WHISPER}" -name 'ggml*' | wc -l)" = '9' ]; then
71+
echo ' (installed) '
72+
fi
73+
echo ''
74+
}
75+
76+
separation_status() {
77+
if [ -d "${SEPARATION}" ] && \
78+
[ "$(find "${SEPARATION}" -name 'htdemucs_v4*' | wc -l)" = '2' ]; then
79+
echo ' (installed) '
80+
fi
81+
echo ''
82+
}
83+
84+
suppression_status() {
85+
if [ -d "${SUPPRESSION}" ] && \
86+
[ "$(find "${SUPPRESSION}" -name 'noise-suppression-denseunet-ll-0001*' | wc -l)" = '2' ] && \
87+
[ "$(find "${SUPPRESSION}/deepfilternet2" -maxdepth 1 -type f | wc -l)" = '6' ] && \
88+
[ "$(find "${SUPPRESSION}/deepfilternet3" -maxdepth 1 -type f | wc -l)" = '6' ]; then
89+
echo ' (installed) '
90+
fi
91+
echo ''
92+
}
93+
94+
resolution_status() {
95+
if [ -d "${RESOLUTION}" ] && \
96+
[ "$(find "${RESOLUTION}" -maxdepth 1 -type f | wc -l)" = '13' ] && \
97+
[ "$(find "${RESOLUTION}/basic" -maxdepth 1 -type f | wc -l)" = '2' ] && \
98+
[ "$(find "${RESOLUTION}/speech" -maxdepth 1 -type f | wc -l)" = '2' ]; then
99+
echo ' (installed) '
100+
fi
101+
echo ''
102+
}
103+
104+
install_musicgen() {
105+
echo "
106+
Downloading Music Generation models from Hugging Face. Please be patient!
107+
"
108+
silent git clone https://huggingface.co/Intel/musicgen-static-openvino "${MUSICGEN_TMP}"
109+
cd "${MUSICGEN_TMP}"
110+
silent git checkout b2ad8083f3924ed704814b68c5df9cbbf2ad2aae
111+
silent git lfs install
112+
silent git lfs pull
113+
mkdir -p "${MUSICGEN}"
114+
silent unzip -o "${MUSICGEN_TMP}/musicgen_small_enc_dec_tok_openvino_models.zip" -d "${MUSICGEN}"
115+
silent unzip -o "${MUSICGEN_TMP}/musicgen_small_mono_openvino_models.zip" -d "${MUSICGEN}"
116+
silent unzip -o "${MUSICGEN_TMP}/musicgen_small_stereo_openvino_models.zip" -d "${MUSICGEN}"
117+
rm -rf "${MUSICGEN_TMP}"
118+
echo "Music Generation models (~2.8GB) successfully installed to ${MUSICGEN}"
119+
}
120+
121+
install_whisper() {
122+
echo "
123+
Downloading Whisper Transcription models from Hugging Face. Please be patient!
124+
"
125+
silent git clone https://huggingface.co/Intel/whisper.cpp-openvino-models "${WHISPER_TMP}"
126+
cd "${WHISPER_TMP}"
127+
silent git lfs install
128+
silent git lfs pull
129+
mkdir -p "${WHISPER}"
130+
silent unzip -o "${WHISPER_TMP}/ggml-base-models.zip" -d "${WHISPER}"
131+
silent unzip -o "${WHISPER_TMP}/ggml-small-models.zip" -d "${WHISPER}"
132+
silent unzip -o "${WHISPER_TMP}/ggml-small.en-tdrz-models.zip" -d "${WHISPER}"
133+
rm -rf "${WHISPER_TMP}"
134+
echo "Whisper Transcription models (~1.5GB) successfully installed to ${WHISPER}"
135+
}
136+
137+
install_separation() {
138+
echo "
139+
Downloading Music Separation models from Hugging Face. Please be patient!
140+
"
141+
silent git clone https://huggingface.co/Intel/demucs-openvino "${SEPARATION_TMP}"
142+
cd "${SEPARATION_TMP}"
143+
silent git checkout 97fc578fb57650045d40b00bc84c7d156be77547
144+
mkdir -p "${SEPARATION}"
145+
cp "${SEPARATION_TMP}/htdemucs_v4."{bin,xml} "${SEPARATION}"
146+
rm -rf "${SEPARATION_TMP}"
147+
echo "Music Separation models (~99MB) successfully installed to ${SEPARATION}"
148+
}
149+
150+
install_suppression() {
151+
echo "
152+
Downloading Noise Suppression models from Hugging Face. Please be patient!
153+
"
154+
silent git clone https://huggingface.co/Intel/deepfilternet-openvino "${SUPPRESSION_TMP}"
155+
cd "${SUPPRESSION_TMP}"
156+
silent git checkout 995706bda3da69da0825074ba7dbc8a78067e980
157+
silent git lfs install
158+
silent git lfs pull
159+
mkdir -p "${SUPPRESSION}"
160+
silent unzip -o "${SUPPRESSION_TMP}/deepfilternet2.zip" -d "${SUPPRESSION}"
161+
silent unzip -o "${SUPPRESSION_TMP}/deepfilternet3.zip" -d "${SUPPRESSION}"
162+
silent wget -O "${SUPPRESSION}/noise-suppression-denseunet-ll-0001.xml" "https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/noise-suppression-denseunet-ll-0001/FP16/noise-suppression-denseunet-ll-0001.xml"
163+
silent wget -O "${SUPPRESSION}/noise-suppression-denseunet-ll-0001.bin" "https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1/noise-suppression-denseunet-ll-0001/FP16/noise-suppression-denseunet-ll-0001.bin"
164+
rm -rf "${SUPPRESSION_TMP}"
165+
echo "Noise Suppression models (~27MB) successfully installed to ${SUPPRESSION}"
166+
}
167+
168+
install_resolution() {
169+
echo "
170+
Downloading Super Resolution models from Hugging Face. Please be patient!
171+
"
172+
silent git clone https://huggingface.co/Intel/versatile_audio_super_resolution_openvino "${RESOLUTION_TMP}"
173+
cd "${RESOLUTION_TMP}"
174+
silent git lfs install
175+
silent git lfs pull
176+
mkdir -p "${RESOLUTION}"
177+
silent unzip -o "${RESOLUTION_TMP}/versatile_audio_sr_base_openvino_models.zip" -d "${RESOLUTION}"
178+
silent unzip -o "${RESOLUTION_TMP}/versatile_audio_sr_ddpm_basic_openvino_models.zip" -d "${RESOLUTION}"
179+
silent unzip -o "${RESOLUTION_TMP}/versatile_audio_sr_ddpm_speech_openvino_models.zip" -d "${RESOLUTION}"
180+
rm -rf "${RESOLUTION_TMP}"
181+
echo "Super Resolution models (~2GB) successfully installed to ${RESOLUTION}"
182+
}
183+
184+
build_model_menu() {
185+
model_menu="
186+
-------------------------------------------------------------------------------------------------
187+
| Audacity OpenVINO™ plugins support several AI models available for download from Hugging Face |
188+
-------------------------------------------------------------------------------------------------
189+
190+
1. Music Generation$(musicgen_status)
191+
2. Whisper Transcription$(whisper_status)
192+
3. Music Separation$(separation_status)
193+
4. Noise Suppression$(suppression_status)
194+
5. Super Resolution$(resolution_status)
195+
6. Exit
196+
197+
Some models are several GB in size, so be mindful of your available disk space and network speed.
198+
199+
To download and install a model, please select an option from the menu above and hit enter: "
200+
}
201+
202+
parse_params() {
203+
verbose='no' # default behavior is to run commands silently
204+
batch_mode='no' # default behavior is interactive mode
205+
206+
while :; do
207+
case "${1-}" in
208+
-h | --help) usage ;;
209+
-v | --verbose) verbose='yes' ;;
210+
-b | --batch) batch_mode='yes' ;;
211+
-?*) echo "Unknown option: $1" && exit 1 ;;
212+
*) break ;;
213+
esac
214+
shift
215+
done
216+
217+
return 0
218+
}
219+
220+
loop_menu() {
221+
while :; do
222+
cd "${SCRIPT_DIR}"
223+
build_model_menu
224+
read -rp "${model_menu}" model_selection
225+
case "${model_selection}" in
226+
1) install_musicgen ;;
227+
2) install_whisper ;;
228+
3) install_separation ;;
229+
4) install_suppression ;;
230+
5) install_resolution ;;
231+
6) exit ;;
232+
*) echo "
233+
Unknown option ${model_selection} selected." ;;
234+
esac
235+
done
236+
}
237+
238+
parse_params "$@"
239+
240+
if ! grep -qw "GenuineIntel" /proc/cpuinfo; then
241+
echo "The OpenVINO™ AI models are only supported on Intel hardware. Exiting."
242+
exit 1
243+
fi
244+
245+
if [ "${SNAP_UID}" -ne 0 ]; then
246+
>&2 echo "
247+
This tool installs models to ${SNAP_DATA},
248+
where write access is only permitted for the root user.
249+
Please re-run the command with sudo:
250+
251+
sudo $(basename "${BASH_SOURCE[0]}")
252+
"
253+
exit 1
254+
fi
255+
256+
if [ "${batch_mode}" = 'yes' ]; then
257+
for model in musicgen whisper separation suppression resolution; do
258+
cd "${SCRIPT_DIR}"
259+
install_"${model}"
260+
done
261+
else
262+
loop_menu
263+
fi

0 commit comments

Comments
 (0)