Skip to content

shi3z/speech-to-speech-japanese

 
 

Repository files navigation

 

Speech To Speech: an effort for an open-sourced and modular GPT4-o

fork from: https://github.com/eustlb/speech-to-speech

Japanese support

Python 3.10で動作確認済み

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 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 protobuf --upgrade
python s2s_pipeline.py --mode local --device mps

MacBookPro M2 Max(32GB)で動作確認済 MacBook M1(16GB)でも動作確認済み( @necobit (https://github.com/necobit) )

📖 Quick Index

Approach

Structure

This repository implements a speech-to-speech cascaded pipeline with consecutive parts:

  1. Voice Activity Detection (VAD): silero VAD v5
  2. Speech to Text (STT): Whisper checkpoints (including distilled versions)
  3. Language Model (LM): Any instruct model available on the Hugging Face Hub! 🤗
  4. Text to Speech (TTS): Parler-TTS🤗

Modularity

The pipeline aims to provide a fully open and modular approach, leveraging models available on the Transformers library via the Hugging Face hub. The level of modularity intended for each part is as follows:

  • VAD: Uses the implementation from Silero's repo.
  • STT: Uses Whisper models exclusively; however, any Whisper checkpoint can be used, enabling options like Distil-Whisper and French Distil-Whisper.
  • LM: This part is fully modular and can be changed by simply modifying the Hugging Face hub model ID. Users need to select an instruct model since the usage here involves interacting with it.
  • TTS: The mini architecture of Parler-TTS is standard, but different checkpoints, including fine-tuned multilingual checkpoints, can be used.

The code is designed to facilitate easy modification. Each component is implemented as a class and can be re-implemented to match specific needs.

Setup

Clone the repository:

git clone https://github.com/eustlb/speech-to-speech.git
cd speech-to-speech

Install the required dependencies:

pip install -r requirements.txt

Usage

The pipeline can be run in two ways:

  • Server/Client approach: Models run on a server, and audio input/output are streamed from a client.
  • Local approach: Uses the same client/server method but with the loopback address.

Server/Client Approach

To run the pipeline on the server:

python s2s_pipeline.py --recv_host 0.0.0.0 --send_host 0.0.0.0

Then run the client locally to handle sending microphone input and receiving generated audio:

python listen_and_play.py --host <IP address of your server>

Local Approach

Simply use the loopback address:

python s2s_pipeline.py --recv_host localhost --send_host localhost
python listen_and_play.py --host localhost

You can pass --device mps to run it locally on a Mac.

Recommended usage

Leverage Torch Compile for Whisper and Parler-TTS:

python s2s_pipeline.py \
	--recv_host 0.0.0.0 \
	--send_host 0.0.0.0 \
	--lm_model_name microsoft/Phi-3-mini-4k-instruct \
	--init_chat_role system \
	--stt_compile_mode reduce-overhead \
	--tts_compile_mode default 

For the moment, modes capturing CUDA Graphs are not compatible with streaming Parler-TTS (reduce-overhead, max-autotune).

Command-line Usage

Model Parameters

model_name, torch_dtype, and device are exposed for each part leveraging the Transformers' implementations: Speech to Text, Language Model, and Text to Speech. Specify the targeted pipeline part with the corresponding prefix:

  • stt (Speech to Text)
  • lm (Language Model)
  • tts (Text to Speech)

For example:

--lm_model_name google/gemma-2b-it

Generation Parameters

Other generation parameters of the model's generate method can be set using the part's prefix + _gen_, e.g., --stt_gen_max_new_tokens 128. These parameters can be added to the pipeline part's arguments class if not already exposed (see LanguageModelHandlerArguments for example).

Notable Parameters

VAD Parameters

  • --thresh: Threshold value to trigger voice activity detection.
  • --min_speech_ms: Minimum duration of detected voice activity to be considered speech.
  • --min_silence_ms: Minimum length of silence intervals for segmenting speech, balancing sentence cutting and latency reduction.

Language Model

  • --init_chat_role: Defaults to None. Sets the initial role in the chat template, if applicable. Refer to the model's card to set this value (e.g. for Phi-3-mini-4k-instruct you have to set --init_chat_role system)
  • --init_chat_prompt: Defaults to "You are a helpful AI assistant." Required when setting --init_chat_role.

Speech to Text

  • --description: Sets the description for Parler-TTS generated voice. Defaults to: "A female speaker with a slightly low-pitched voice delivers her words quite expressively, in a very confined sounding environment with clear audio quality. She speaks very fast."

  • --play_steps_s: Specifies the duration of the first chunk sent during streaming output from Parler-TTS, impacting readiness and decoding steps.

Citations

Silero VAD

@misc{Silero VAD,
  author = {Silero Team},
  title = {Silero VAD: pre-trained enterprise-grade Voice Activity Detector (VAD), Number Detector and Language Classifier},
  year = {2021},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/snakers4/silero-vad}},
  commit = {insert_some_commit_here},
  email = {hello@silero.ai}
}

Distil-Whisper

@misc{gandhi2023distilwhisper,
      title={Distil-Whisper: Robust Knowledge Distillation via Large-Scale Pseudo Labelling},
      author={Sanchit Gandhi and Patrick von Platen and Alexander M. Rush},
      year={2023},
      eprint={2311.00430},
      archivePrefix={arXiv},
      primaryClass={cs.CL}
}

Parler-TTS

@misc{lacombe-etal-2024-parler-tts,
  author = {Yoach Lacombe and Vaibhav Srivastav and Sanchit Gandhi},
  title = {Parler-TTS},
  year = {2024},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/huggingface/parler-tts}}
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%