A module kit for Fast RTC in Japanese
Project description
fastrtc-jp
fastrtc用の日本語TTSとSTT追加キット(日本語音声合成・認識モジュール)
概要
fastrtcは高性能なリアルタイム通信フレームワークですが、現状では日本語の音声合成(TTS)および音声認識(STT)機能が十分に対応していません。このプロジェクトは、fastrtcに日本語対応の音声処理機能を追加するための拡張パッケージです。
主な機能:
- 日本語に特化した音声合成モデル(Voicevox、gTTS)
- 日本語に対応した音声認識モデル(Vosk、Google Speech Recognition)
fastrtcの詳細な使い方については、fastrtc公式ドキュメントを参照してください。
システム要件
- Python 3.11以上
- 各モデルの追加要件は以下の「インストール」セクションを参照
インストール
基本的な使い方として、Python仮想環境を作成してからpipでインストールすることをお勧めします。
# 仮想環境の作成と有効化(オプション)
python -m venv fastrtc-env
source fastrtc-env/bin/activate # Linuxの場合
# または
.\fastrtc-env\Scripts\activate # Windowsの場合
# 基本パッケージのインストール
pip install fastrtc-jp
追加モジュール
必要に応じて、以下の追加パッケージをインストールしてください:
音声合成(TTS)
VoicevoxTTSModelを使用する場合: Voicevoxエンジンが必要です。Voicevox公式を参照し、APIでアクセスできる環境を準備してください。
GTTSModelを使用する場合:
pip install fastrtc-jp[gtts]
インターネット接続が必要です。
音声認識(STT)
VoskSTTを使用する場合:
pip install fastrtc-jp[vosk]
詳細はVoskの公式を参照してください。 一応、日本語のモデルを自動でダウンロードするようにしています。
GoogleSTTを使用する場合:
pip install fastrtc-jp[sr]
インターネット接続が必要です。
提供モデル一覧
| クラス | 説明 | 追加パッケージ | 特徴 |
|---|---|---|---|
| VoicevoxTTSModel | Voicevoxのapiで音声合成するクラス | - | 高品質な日本語音声、多様な話者、感情表現が可能 |
| GTTSModel | Google Text-to-Speechで音声合成するクラス | gtts | インターネット接続が必要、自然な発話 |
| VoskSTT | Voskエンジンで音声認識するクラス | vosk | オフライン動作可能、軽量 |
| GoogleSTT | SpeechRecognizerのGoogleエンジンで音声認識するクラス | sr | 高精度、インターネット接続が必要 |
使用例
基本的なエコーバックサンプル
マイクの音声をそのままスピーカーにエコーバックするシンプルな例です。
import sys, os
import numpy as np
from fastrtc import ReplyOnPause
from fastrtc.reply_on_pause import AlgoOptions
from fastrtc.stream import Stream
"""
マイクの音声をそのままスピーカーにエコーバックするだけのサンプル
"""
def echoback(audio: tuple[int, np.ndarray]):
print(f"shape:{audio[1].shape} dtype:{audio[1].dtype} {audio[0]}Hz {audio[1].shape[1]/audio[0]}秒の音声が入力されました。")
yield audio
def example_echoback():
algo_options = AlgoOptions(
audio_chunk_duration=0.6,
started_talking_threshold=0.5,
speech_threshold=0.1,
)
stream = Stream(
handler=ReplyOnPause(
echoback,
algo_options=algo_options,
input_sample_rate=16000,
output_sample_rate=16000,
),
modality="audio",
mode="send-receive",
)
stream.ui.launch()
if __name__ == "__main__":
example_echoback()
Voicevoxで音声合成するサンプル
import sys, os
import numpy as np
from fastrtc import ReplyOnPause
from fastrtc.reply_on_pause import AlgoOptions
from fastrtc.stream import Stream
from fastrtc_jp.text_to_speech.voicevox import VoicevoxTTSModel, VoicevoxTTSOptions
"""
voicevoxで音声合成するだけのサンプル
"""
tts_model = VoicevoxTTSModel() # デフォルトはlocalhostの50021ポートに接続
voicevox_opt = VoicevoxTTSOptions(
speaker=8, # つむぎ
speedScale=1.0, # 話速(1.0が標準)
)
def voicevox(audio: tuple[int, np.ndarray]):
print(f"shape:{audio[1].shape} dtype:{audio[1].dtype} {audio[0]}Hz {audio[1].shape[1]/audio[0]}秒の音声が入力されました。")
response = "やっほー、今日も元気だ。やきとり食べよう。"
for audio_chunk in tts_model.stream_tts_sync(response, voicevox_opt):
print("Sending audio")
yield audio_chunk
def example_voicevox():
algo_options = AlgoOptions(
audio_chunk_duration=0.6,
started_talking_threshold=0.5,
speech_threshold=0.1,
)
stream = Stream(
handler=ReplyOnPause(
voicevox,
algo_options=algo_options,
input_sample_rate=16000,
output_sample_rate=16000,
),
modality="audio",
mode="send-receive",
)
stream.ui.launch()
if __name__ == "__main__":
example_voicevox()
音声認識と音声合成を組み合わせたサンプル
import sys, os
import numpy as np
from fastrtc import ReplyOnPause
from fastrtc.reply_on_pause import AlgoOptions
from fastrtc.stream import Stream
from fastrtc_jp.speech_to_text.sr_google import GoogleSTT
# from fastrtc_jp.speech_to_text.vosk import VoskSTT
from fastrtc_jp.text_to_speech.voicevox import VoicevoxTTSModel, VoicevoxTTSOptions
# from fastrtc_jp.text_to_speech.gtts import GTTSModel, GTTSOptions
"""
マイクの音声をSTT->TTSしてエコーバックするサンプル
"""
# 音声認識モデルの初期化
stt_model = GoogleSTT()
# stt_model = VoskSTT() # Voskを使用する場合
# 音声合成モデルの初期化
tts_model = VoicevoxTTSModel()
voicevox_opt = VoicevoxTTSOptions(
speaker=8, # つむぎ
speedScale=1.0,
)
# tts_model = GTTSModel() # gTTSを使用する場合
def echoback(audio: tuple[int, np.ndarray]):
print(f"shape:{audio[1].shape} dtype:{audio[1].dtype} {audio[0]}Hz {audio[1].shape[1]/audio[0]}秒の音声が入力されました。")
# 音声認識
user_input = stt_model.stt(audio)
print(f"音声認識結果: {user_input}")
# 認識した文章をそのまま音声合成してエコーバック
response = user_input
for audio_chunk in tts_model.stream_tts_sync(response, voicevox_opt):
print("Sending audio")
yield audio_chunk
def example_echoback():
algo_options = AlgoOptions(
audio_chunk_duration=0.6,
started_talking_threshold=0.5,
speech_threshold=0.1,
)
stream = Stream(
handler=ReplyOnPause(
echoback,
algo_options=algo_options,
input_sample_rate=16000,
output_sample_rate=16000,
),
modality="audio",
mode="send-receive",
)
stream.ui.launch()
if __name__ == "__main__":
example_echoback()
モデル詳細
VoicevoxTTSModel
VOICEVOXは、無料で使える高品質な日本語音声合成エンジンです。
初期化オプション:
host: Voicevox APIのホスト(デフォルト: "localhost")port: Voicevox APIのポート(デフォルト: 50021)
VoicevoxTTSOptions:
speaker: 話者ID(整数)speedScale: 話速スケール(デフォルト: 1.0)- その他のパラメータについてはVOICEVOX APIリファレンスを参照
GTTSModel
Google Text-to-Speechを使用した音声合成モデルです。
GTTSOptions:
lang: 言語コード(デフォルト: "ja")slow: ゆっくり話すかどうか(デフォルト: False)
VoskSTT
Voskは、オフラインで動作する音声認識エンジンです。
初期化オプション:
model_path: Voskモデルのパス
GoogleSTT
Googleの音声認識エンジンを使用します。インターネット接続が必要です。
ライセンス
このプロジェクトはMITライセンスの下で公開されています。詳細はLICENSEファイルを参照してください。
貢献
バグレポート、機能リクエスト、プルリクエストなど、あらゆる形での貢献を歓迎します。
謝辞
fastrtcの詳細な使い方については、fastrtc公式ドキュメントを参照してください。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastrtc_jp-0.1.1.tar.gz.
File metadata
- Download URL: fastrtc_jp-0.1.1.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8faeed4540e622b82493520e3fe28e94202b0fc341e3a92686740d3f6e0b8e13
|
|
| MD5 |
a3eede0b40b0585a637559ed0a2c3a93
|
|
| BLAKE2b-256 |
51c964ec5eb46a8e631e0a007b23cdb97a80bfb2ff87b5c1f04b7a34d1262bd6
|
File details
Details for the file fastrtc_jp-0.1.1-py3-none-any.whl.
File metadata
- Download URL: fastrtc_jp-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b155b2afa337666f92e8b2a4e76ff8cccbc92eb9a1a51807a8b30c94e9da7f4
|
|
| MD5 |
f9d0db89bab025765336808f6defd451
|
|
| BLAKE2b-256 |
92502d648410978441fc48477bb6c04ac8816414748aad738c26403f4ff00d80
|