# ベースイメージとしてPython 3.11.2を使用
FROM python:3.11.2

# パッケージリストを更新し、音声処理に必要なライブラリをインストール
RUN apt update && \
    apt-mark hold debian-kernel* && \
    apt-mark hold firmware* && \
    apt -y upgrade 

RUN apt install -y \
    libasound2-dev=1.2.4-1.1  \
    portaudio19-dev=19.6.0-1.1 \
    alsa-utils=1.2.4-1  \
    flac=1.3.3-2+deb11u2

# APTのキャッシュを削除
RUN apt clean 

# ユーザー情報を設定するための変数
ARG USERNAME=mike
ARG GROUPNAME=user
ARG UID=1000
ARG GID=1000

# 指定したUIDとGIDで新しいグループとユーザーを作成し、音声グループにも追加
RUN groupadd -g $GID $GROUPNAME && \
    useradd -m -s /bin/bash -u $UID -g $GID -G audio $USERNAME

# 作成したユーザーを使用する
USER $USERNAME

# 作業ディレクトリを設定
WORKDIR /opt/$USERNAME/

# 必要なPythonパッケージをインストール
RUN pip install -U --no-cache-dir pip==24.3.1 
RUN pip install --no-cache-dir simpleaudio==1.0.4 
RUN pip install --no-cache-dir wave==0.0.2
RUN pip install --no-cache-dir requests==2.32.3 
RUN pip install --no-cache-dir SpeechRecognition==3.11.0
RUN pip install --no-cache-dir PyAudio==0.2.14
RUN pip install --no-cache-dir sounddevice==0.5.1

# 実行コマンドを設定
CMD ["/bin/bash"]
