Skip to main content

Soramimi (phonetic parody) lyrics generator — Python port of the Soramimic engine

Project description

soramimic

空耳(替え歌)歌詞を自動生成する Soramimic エンジンの Python ライブラリです。 本体( soramimic/soramimic の frontend/src/lib )の挙動互換移植で、同じ入力・同じ単語リストから本体と同じ空耳を生成します。

開発中(0.x)。API は変わる可能性があります。

インストール

pip install soramimic          # コア(トークナイザなし)
pip install "soramimic[mecab]" # fugashi + ipadic トークナイザ込み

使い方

from soramimic import create_soramimic, load_default_data
from soramimic.tokenizers.mecab import MeCabTokenizer  # 要 soramimic[mecab]

tok = MeCabTokenizer()
app = create_soramimic(
    **load_default_data(),  # 同梱の辞書データ(漢字読み・英語カナ・音類似度など)
    tokenize_sentenses=tok.tokenize,
    get_yomi=tok.get_yomi,
)

# 単語リスト: tidy CSV (soramimic-wordlists 形式) または1行1語のプレーンテキスト。
# 試しやすいようにサンプル(nations=国名, sekitsui=脊椎動物, stations=駅名)を同梱している
from soramimic import load_sample_wordlist

db = app.word_list.parse_tidy(load_sample_wordlist("nations"), "")  # 第2引数はwhere式

results = app.soramimi_maker.generate(["夜の街を駆け抜ける"], db, {})
for line in results:
    print(" / ".join(w["surface"] for w in line))
# => ヨルダン / マリ / オマーン / ペルー / ペルー

自前の単語リストを使う場合は同形式のCSVテキストを parse_tidy に渡します。 同梱サンプルは権利上の配慮から事実データ(国名・生物名・駅名)のみです。

トークナイザは差し替え可能です( soramimic.tokenizer.Tokenizer プロトコル参照)。 kuromoji.js 互換のトークン dict( surface_form / pronunciation / pos …、未知語は "*" )を返せば何でも使えます。 事前にトークナイズ済みの入力からは generate_from_tokens() で生成できます(固定区間 locks による部分再生成にも対応)。

本体JSとの互換性

  • モジュールは本体 frontend/src/lib の各JSファイルと1:1対応です( kanaToSyllable.jskana_to_syllable.py など)。
  • 互換性はゴールデンテストで担保しています。tools/generate_golden.mjs が本体JSを Node で直接実行して期待出力( tests/golden/*.json )を生成し、pytest で Python 出力との完全一致を検証します。本体更新への追従時は次で再生成してください:
node tools/generate_golden.mjs <soramimicリポジトリのルート> tests/golden
uv run pytest tests/test_golden.py
  • JS実装の癖(オブジェクトのキー列挙順、共有ミューテーション、既知の細かなバグを含む)も出力互換のため忠実に再現しています。詳細は各モジュールのコメント参照。

開発

uv sync --all-extras
uv run pytest
uv run ruff check .

License

MIT。同梱の英語発音データ( english-kana.json )は CMUdict 由来です( src/soramimic/data/english-kana.LICENSE 参照)。

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

soramimic-0.1.2.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

soramimic-0.1.2-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file soramimic-0.1.2.tar.gz.

File metadata

  • Download URL: soramimic-0.1.2.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for soramimic-0.1.2.tar.gz
Algorithm Hash digest
SHA256 683487dc5f15e1541cce1627887403bfd8fb3c4819e7bd3529694663c236d3f7
MD5 d7a01a98f461dad28b61c965c22f1037
BLAKE2b-256 99828c54802a7f482c7836577bf69c6e98bd78675b765b1cb8e15fbb09bac92e

See more details on using hashes here.

Provenance

The following attestation bundles were made for soramimic-0.1.2.tar.gz:

Publisher: publish.yml on soramimic/soramimic-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file soramimic-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: soramimic-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for soramimic-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5046f4e42798665241422fdcca1850ec360fb1ac3758d9d3f1ad3a2795850eb7
MD5 7688eadcd88cf27a89fbf9b724ac706b
BLAKE2b-256 a3bc9ff640c79ee671097914b7d94db60d720f93a54a44837ddcf254b72ea4be

See more details on using hashes here.

Provenance

The following attestation bundles were made for soramimic-0.1.2-py3-none-any.whl:

Publisher: publish.yml on soramimic/soramimic-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page