見出し画像

MacBook Proでspeech-to-speech-japaneseを試してみる

shi3zさん公開のspeech-to-speech-japaneseを手元のMacBook Pro(M3)で、早速試してみます。

githubはこちら。


1. 準備

仮想環境構築

brewコマンドでpython 3.11をインストールします。(3.12ですと、pip install ReazonSpeech/pkg/nemo-asr 実行時にdistutilsパッケージがない等のエラーが発生するため)

brew install python@3.11
python3.11 -m vevn s2s-ja.3.11
cd $_
source bin/activate

MeloTTSのインストール時に必要となるMeCabライブラリをbrew経由でインストールしておきます。

# MeCab
brew install mecab

アプリ環境構築

READMEにあるJapanese supportセクションの手順をベースに、少しパッケージ(wheel, lightning_whisper_mlx)を追加し、セットアップします。

git clone https://github.com/shi3z/speech-to-speech-japanese.git
cd speech-to-speech-japanese
#
pip install git+https://github.com/nltk/nltk.git@3.8.2
#
git clone https://github.com/reazon-research/ReazonSpeech
pip install wheel
pip install Cython
pip install ReazonSpeech/pkg/nemo-asr
#
git clone https://github.com/myshell-ai/MeloTTS
cd MeloTTS
pip install -e .
python -m unidic download
cd ..
#
pip install -r requirements.txt
pip install transformers==4.44.1
pip install mlx-lm
pip install lightning_whisper_mlx
pip install --upgrade  protobuf

2. 試してみる

満を持して起動です。

python s2s_pipeline.py --mode local --device mps

以下のようにロードまで完了したら、

(s2s-ja.3.11) noguchi@noguchis-MacBook-Pro speech-to-speech-japanese % python s2s_pipeline.py --mode local --device mps
/Users/noguchi/devsecops/venv/s2s-ja.3.11/lib/python3.11/site-packages/transformers/tokenization_utils_base.py:1601: FutureWarning: `clean_up_tokenization_spaces` was not set. It will be set to `True` by default. This behavior will be depracted in transformers v4.45, and will be then set to `False` by default. For more details check this issue: https://github.com/huggingface/transformers/issues/31884
  warnings.warn(
Using cache found in /Users/noguchi/.cache/torch/hub/snakers4_silero-vad_master
 mlx-community/Llama-3-Swallow-8B-Instruct-v0.1-8bit
Fetching 7 files: 100%|████████████████████████████████████████████████████████████████████████| 7/7 [00:00<00:00, 33631.30it/s]

マイクに向かって、ゆっくりと滑舌よく語りかけます。

ドラえもんとはなにか?

Transcribing:   0%|                                                                                       | 0/1 [00:00<?, ?it/s]Python(83052) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.
Python(83053) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.
[NeMo W 2024-08-22 02:54:20 nemo_logging:393] /Users/noguchi/devsecops/venv/s2s-ja.3.11/lib/python3.11/site-packages/nemo/collections/asr/parts/preprocessing/features.py:417: FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead.
      with torch.cuda.amp.autocast(enabled=False):
    
Beam search progress:: 100%|██████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  2.70sample/s]
Transcribing: 100%|███████████████████████████████████████████████████████████████████████████████| 1/1 [00:03<00:00,  3.93s/it]
USER: ドラえもんとはなにか?
[{'role': 'system', 'content': 'あなたは日本語に堪能な友人です。英語を使ってはいけません。全て日本語で回答します. You must answer in Japanese'}, {'role': 'user', 'content': 'ドラえもんとはなにか?, '}]
cur:
ASSISTANT: ドラえもんは、藤子・エフ・不二雄(藤子不二雄エー)が作成した日本の漫画とアニメのキャラクターです。
cur:
ASSISTANT: ドラえもんは、未来から来た猫型ロボットで、主人公の小学生、野比のび太の友達です。
cur:
ASSISTANT: ドラえもんは、未来の道具を持ち歩き、のび太やその友達たちを助けることができます。
cur:
ASSISTANT: ドラえもんは、日本の文化に大きな影響を与え、世界中で愛されています。
cur:
generated_text:ドラえもんは、藤子・F・不二雄(藤子不二雄A)が作成した日本の漫画とアニメのキャラクターです。ドラえもんは、未来から来た猫型ロボットで、主人公の小学生、野比のび太の友達です。ドラえもんは、未来の道具を持ち歩き、のび太やその友達たちを助けることができます。ドラえもんは、日本の文化に大きな影響を与え、世界中で愛されています。<|eot_id|><|begin_of_text|>Doraemon is a
ASSISTANT: <|eot_id|>
  

喋った喋った、マックが日本語で喋った!

のび太とは?

Transcribing:   0%|                                                                                       | 0/1 [00:00<?, ?it/s]Python(83159) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.
Python(83160) MallocStackLogging: can't turn off malloc stack logging because it was not enabled.
[NeMo W 2024-08-22 02:58:42 nemo_logging:393] /Users/noguchi/devsecops/venv/s2s-ja.3.11/lib/python3.11/site-packages/nemo/collections/asr/parts/preprocessing/features.py:417: FutureWarning: `torch.cuda.amp.autocast(args...)` is deprecated. Please use `torch.amp.autocast('cuda', args...)` instead.
      with torch.cuda.amp.autocast(enabled=False):
    
Beam search progress:: 100%|██████████████████████████████████████████████████████████████████| 1/1 [00:00<00:00,  3.57sample/s]
Transcribing: 100%|███████████████████████████████████████████████████████████████████████████████| 1/1 [00:07<00:00,  7.19s/it]
USER: のび太とは?
[{'role': 'system', 'content': 'あなたは日本語に堪能な友人です。英語を使ってはいけません。全て日本語で回答します. You must answer in Japanese'}, {'role': 'user', 'content': 'ドラえもんとはなにか?, '}, {'role': 'assistant', 'content': 'ドラえもんは、藤子・F・不二雄(藤子不二雄A)が作成した日本の漫画とアニメのキャラクターです。ドラえもんは、未来から来た猫型ロボットで、主人公の小学生、野比のび太の友達です。ドラえもんは、未来の道具を持ち歩き、のび太やその友達たちを助けることができます。ドラえもんは、日本の文化に大きな影響を与え、世界中で愛されています。<|eot_id|><|begin_of_text|>Doraemon is a'}, {'role': 'user', 'content': 'のび太とは?, '}]
cur:
ASSISTANT: のび太は、ドラえもんの主人公で、小学生です。
cur:
ASSISTANT: 彼は、常に怠け者で、勉強や運動に堪能な子ではありません。
cur:
ASSISTANT: 彼は、ドラえもんの助けを借りて、常に問題を解決し、友達と遊びます。
cur:
ASSISTANT: のび太は、ドラえもんの友達であり、家族でもあります。
cur:
ASSISTANT: 彼は、ドラえもんの道具を使って、常に新しいことを学び、成長していきます。
cur:
cur:
cur:
generated_text:のび太は、ドラえもんの主人公で、小学生です。彼は、常に怠け者で、勉強や運動に堪能な子ではありません。彼は、ドラえもんの助けを借りて、常に問題を解決し、友達と遊びます。のび太は、ドラえもんの友達であり、家族でもあります。彼は、ドラえもんの道具を使って、常に新しいことを学び、成長していきます。<|eot_id|><|eot_id|>assistant<|eot_id|>のび太は、ドラ
ASSISTANT: <|eot_id|>
ASSISTANT: <|eot_id|>
ASSISTANT: assistant<|eot_id|>

日本語で語りかけたら、MacBook Proが日本語で回答してくれる!
日本語で会話できるの、すばらしい。

3. 使用リソース

アクティビティモニタで確認しました。
起動直後: 12.54GBほど。

会話しているとき: 14.49GBほど。

この記事が気に入ったらサポートをしてみませんか?