amivoice-client-library-python
AmiVoice API を利用して音声認識アプリケーションを開発するための Python クライアントライブラリと、そのサンプルプログラムを提供しています。 本ライブラリは MIT License で提供します。
パッケージ構成
src/
└── amivoice/
├── __init__.py # 公開API
├── client.py # 同期HTTP・WebSocket音声認識
├── async_client.py # 非同期HTTP音声認識(同期メソッド提供)
├── _*.py # 標準ライブラリによるHTTP・WebSocket通信と設定の処理
├── constants.py # 接続エンジンと音声フォーマット
├── models.py # 認識結果とイベント
├── async_models.py # 非同期HTTPジョブと認識結果モデル
├── dictionary.py # ユーザー辞書の管理
├── api_key.py # APIキーの発行
├── sentiment_analysis.py # 感情パラメータの定義取得
├── grammar.py # ルールグラマの指定
├── settings.py # 認識設定とクライアント既定値の継承指定
└── exceptions.py # 公開例外
クイックスタート
Python 3.11 以降に対応しています。アプリケーションから利用する場合は、配布パッケージをインストールします。
pip install amivoice-api-client
API キーを環境変数AMIVOICE_API_KEYに設定してから実行してください。
クライアントは環境変数からキーを読み取るため、ソースコードや実行時の引数にキーを書く必要はありません。
from amivoice import AmiVoiceClient, Engine, RecognitionSettings
client = AmiVoiceClient(settings=RecognitionSettings(grammar_file_names=Engine.A_GENERAL))
result = client.transcribe("audio.wav")
print(result.text)
認識設定はRecognitionSettingsにまとめてsettingsへ渡します。旧 API の個別の認識引数は使用できません。
RecognitionSettings.grammar_file_namesは HTTP と WebSocket の両方で必須です。HTTP ではヘッダ付き音声であればcodecを省略できます。
WebSocket ではcodecも必ず指定してください。
長時間の音声やバッチ処理には、非同期 HTTP 音声認識 API(v2)を利用できる AmiVoiceAsyncClient も用意されています。
Python の async / await 構文ではなく通常の同期(ブロッキング)メソッドを提供し、ジョブの登録(submit)、状態取得(get_job)、完了待機(wait)を行えます。
非同期 HTTP(v2)では、話者ダイアライゼーションや感情分析(RecognitionSettings.sentiment_analysis)の指定および結果取得にも対応しています。
詳細な利用方法は以下のガイドを参照してください。
クライアント既定値の継承(USE_CLIENT_DEFAULT)
コンストラクタ(AmiVoiceClient、AmiVoiceAsyncClient)では、settingsを省略するかsettings=Noneを指定すると空の認識設定を表します。
モジュール関数transcribe()のsettingsはRecognitionSettings型の必須キーワード引数です。省略するとTypeErrorになり、NoneやUSE_CLIENT_DEFAULTなどのRecognitionSettings以外の値を指定するとクライアント生成や通信の前にConfigurationErrorを送出します。空のRecognitionSettings()は型として有効ですが、必須のgrammar_file_namesが不足するためConfigurationErrorになります。
クライアントインスタンスの認識メソッド(client.transcribe()、client.stream()、client.submit())では、settingsを省略するかUSE_CLIENT_DEFAULT(型はUseClientDefault)を指定すると、クライアントの設定を継承します。空のRecognitionSettings()もすべての項目を継承します。
インスタンスメソッドの呼び出し時にsettings=Noneは指定できず、通信する前にConfigurationErrorを送出します。クライアントの設定とは別の設定で認識する場合は、新しいクライアントを作成するか、RecognitionSettings(...)で必要な項目を明示して上書きしてください。
RecognitionSettingsの各項目は、省略またはUSE_CLIENT_DEFAULTで継承し、Noneで解除します。Falseや0は解除ではなく明示値です。
プロキシ、通信タイムアウト、接続 URL、raise_on_error、完了待機の引数は、引き続き独立した引数です。
同期クライアントのコンストラクタでは、URL 引数にUSE_CLIENT_DEFAULTを指定すると既定 URL を選択します。
非同期クライアントのコンストラクタのapi_urlは URL 文字列のみを受け付けます。
呼び出し時のapi_url=USE_CLIENT_DEFAULTは、カスタム URL も含めてクライアントの接続先を継承し、既定 URL へリセットしません。URL にNoneは指定できません。
ラッパー関数などで引数をそのまま転送する場合も、未指定の既定値にUSE_CLIENT_DEFAULTを使用します。
from amivoice import (
USE_CLIENT_DEFAULT,
AmiVoiceClient,
Engine,
RecognitionResult,
RecognitionSettings,
UseClientDefault,
)
def recognize_speech(
audio: bytes,
*,
client: AmiVoiceClient,
confidence_level: float | None | UseClientDefault = USE_CLIENT_DEFAULT,
) -> RecognitionResult:
return client.transcribe(audio, settings=RecognitionSettings(confidence_level=confidence_level))
client = AmiVoiceClient(
settings=RecognitionSettings(grammar_file_names=Engine.A_GENERAL, confidence_level=0.2)
)
result = recognize_speech(b"RIFF...", client=client)
公式仕様
最新の公式仕様は以下のマニュアルをご確認ください。
Metadata
Release files for amivoice-api-client 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| amivoice_api_client-1.0.0.tar.gz | 62.8 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| amivoice_api_client-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 139.6 kB
Release files / amivoice_api_client-1.0.0.tar.gz
| Download URL | amivoice_api_client-1.0.0.tar.gz |
|---|---|
| Size | 62.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
241e1ee300420be78938d51165ed2c4c8ac10788a8cc4cbbb84621a203f1af60
|
|
BLAKE2b-256 checksum How to use checksums |
5ee839034bbb405540c266d6e2e03b5947933b0da1f39a165426182eeb4b3554
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / amivoice_api_client-1.0.0-py3-none-any.whl
| Download URL | amivoice_api_client-1.0.0-py3-none-any.whl |
|---|---|
| Size | 76.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2e1e57064a0f58370a2e18b3ba34d01686e447260c1751a61fe82797ba23ee1e
|
|
BLAKE2b-256 checksum How to use checksums |
e24574fca2a0d45811199ae1a8d1c7a72c766af2b63fa532e67a01a5c3ae0d71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for amivoice-api-client 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for amivoice_api_client-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.