Jetson Orin Nanoで音声認識:ROS2とWhisper.cppのセットアップ
Jetson Orin Nanoで音声認識:ROS2とWhisper.cppのセットアップ
NVIDIA Jetson Orin NanoでWhisper.cppを使用した音声認識システムをROS2環境で構築してみました。
後々、ROS2のトピックを使用して音声認識結果を取得できるようにするため、whisper_rosを使用します。
ツールのインストール
colconやrosdepなどのROS2のビルドツールをインストールします。
sudo apt update
sudo apt install -y ros-dev-tools
CUDAのインストール
SDK ManagerでCUDAをインストールしている場合は、以下のインストールは不要です。
sudo apt install -y cuda-toolkit-12-6 cuda-nvcc-12-6
libportaudio2のインストール
PortAudioを使用して音声を取得するために、portaudio19-devをインストールします。
sudo apt install -y portaudio19-dev
作業ディレクトリの作成
mkdir -p ~/ros2-whisper-sample/src
whisper.cppのクローン
cd ~/ros2-whisper-sample/src
git clone https://github.com/ggerganov/whisper.cpp
whisper_rosのクローン
cd ~/ros2-whisper-sample/src
git clone https://github.com/mgonzs13/audio_common.git
git clone https://github.com/mgonzs13/whisper_ros.git
必要なパッケージのインストール
cd ~/ros2-whisper-sample
rosdep install --from-paths src --ignore-src -r -y
colcon build --cmake-args -DGGML_CUDA=ON -DONNX_GPU=ON
whisper.cppのビルドに2時間程度かかるので、しばらく待ちます。
Jetson Orin Nanoにマイク付きのWebカメラを接続
今回はAliexpressで購入したFull HDのマイク付きWebカメラを使用します。
Jetson Orin NanoのUSBポートに接続します。
Settingsアプリを開き、Soundを選択し、Input DeviceでMicrophone - WebCameraを選択します。
ここで、Settingsアプリが開いたままだと音声認識が正常に機能しないので、Settingsアプリは閉じます。
whisper_rosのソースコードの修正
日本語の音声認識実行時に、エラーが発生したので、
以下のように、whisper_rosのソースコードを修正して、再ビルドします。
ファイルは以下の場所にあります。
~/ros2-whisper-sample/src/whisper_ros/whisper_ros/src/whisper_ros/whisper_base_node.cpp
177行目付近を以下のように修正します。
- this->wparams.suppress_regex = suppress_regex.c_str();
+ this->wparams.suppress_regex = suppress_regex.empty() ? nullptr : suppress_regex.c_str();
colcon buildの実行
cd ~/ros2-whisper-sample
colcon build --cmake-args -DGGML_CUDA=ON -DONNX_GPU=ON
source install/setup.bash
音声認識の実行
ros2 launch whisper_bringup whisper.launch.py \
language:=ja \
stream:=True
音声認識の確認
別のターミナルを開き、以下のコマンドを実行して、音声認識結果を確認します。
source install/setup.bash
ros2 topic echo /whisper/transcription
Webカメラのマイクに向かって話しかけると、音声認識結果が表示されます。
Discussion