Skip to main content

Quran Transcript

بفضل الله وحده عز وجل نقدم الرسم الصوتي للقرآن الكريم الملم بجل قواعد التجويد وصفات الحوف

PyPI Python Versions Google Colab

quran-transcript package

🆕 الإصدار 0.7.1: تفسير أخطاء التلاوة ومواضعها في النص العثماني (Version 0.7.1: Recitation Error Explanation and Uthmani Error Positions)

📍 تحديد موضع قواعد التجويد في النص العثماني (Uthmani Ground-Truth Positions for Tajweed Rules)

  • أصبحت TajweedRuleMetadata تتتبع موضع القاعدة في الرسم العثماني بجانب موضعها الصوتي عبر uth_pivot وuth_deps، إلى جانب pivot وdeps (Tajweed metadata now tracks Uthmani positions through uth_pivot/uth_deps in addition to phonetic pivot/deps).
  • تعرض ExplainedTajweedRule الحقول ph_pivot, ph_deps, uth_pivot, uth_deps, tag, وgolden_len جاهزة للعرض أو التسلسل (Explained snapshots expose both coordinate spaces with ph_pivot/ph_deps and uth_pivot/uth_deps, plus tag and golden_len).
  • تحمل قوائم قواعد التجويد المرجعية والمدرجة والمستبدلة والمفقودة داخل ReciterError مواضعها العثمانية، ما يسهّل ربط الخطأ بموضعه في النص العثماني (Reference, inserted, replaced, and missing rule lists in ReciterError now carry Uthmani positions, making it easier to map an error back to the Uthmani text).

🧠 تحسينات تفسير أخطاء التلاوة (Recitation Error Explanation Improvements)

  • أعادت ReciterErrPatern.find_all() كائن ReciterErrPatMatches الذي يحتوي على errors وcovered_alignments بدلاً من قائمة أخطاء فقط (find_all now returns ReciterErrPatMatches with .errors and .covered_alignments).
  • أصبحت check_group تستقبل أنواع قواعد التجويد كوسيط ثالث: (ref_group, pred_group, rule_types) (check_group callbacks now receive the reference rule types as a third argument).
  • توسّعت الأنماط المضمنة لتغطية أحكام النون الساكنة والتنوين، وأحكام الميم الساكنة، والوقف العارض، والإدغام الكامل، والألفات السبعة، والتقاء الساكنين، وهمزة الوصل، واجتماع همزتين (Expanded built-in patterns to cover noon and tanween rules, meem rules, waqf, complete idgham, the seven alifs, iltiqaa sakinayn, hamzat wasl, and two hamzas).
  • التفاصيل والأمثلة في قسم «أنماط أخطاء التلاوة» أدناه (See the “Reciter Error Patterns” section below for details and examples).

🖼️ مثال لتفسير خطأ تلاوة (A Sample Recitation Error Explanation)

  • يتوفر مثال جاهز لتقرير HTML يوضح مواضع الأخطاء وقواعد التجويد المرجعية وطريقة تظليلها (A ready-made HTML report example shows error spans, reference Tajweed rules, and highlight behavior).
  • افتح مثال تفسير خطأ التلاوة (Open the sample recitation error explanation).
  • التفاصيل وطريقة التوليد في قسم «مثال لتفسير خطأ تلاوة» أدناه (See the detailed section below for usage and generation).

📌 تنبيه للمستخدمين القادمين من الإصدار 0.6.x: تغيّر شكل ReciterError بالكامل في 0.7.x — الحقول، وقوائم قواعد التجويد، ومعلومات الحركات. يرجى مراجعة قسم «كائنات تحليل الأخطاء» وتحديث الكود قبل الترقية.

Note for users upgrading from 0.6.x: ReciterError changed completely in 0.7.x — its fields, Tajweed-rule lists, and tashkeel information. Please review the “Error Analysis Dataclasses” section and update your code before upgrading.

🆕 ما الجديد في الإصدار 0.7.0 (What's New in Version 0.7.0)

⚡ أداء التحويل الصوتي (Phonetization Performance)

  • إعادة كتابة تتبع خرائط المواقع: إزاحات كسولة لكل كتلة (lazy per-block offsets) بدلاً من تحديث كل موضع عند كل عملية، مع بحث خطي للمدى القصير ودمج أسرع لأجزاء قواعد التجويد (Rewrote position-mapping tracking: lazy per-block offsets instead of updating every position on each operation, a linear search for short ranges, and faster tajweed-part merging).
  • العملية الصوتية الكاملة لأطول آية Aya(2, 282) انخفضت من ~150ms إلى ~11ms على جهاز ضعيف — نحو 13× أسرع (The full phonetization of the longest aya Aya(2, 282) dropped from ~150ms to ~11ms on a poor laptop — about 13× faster).
  • التفاصيل الكاملة في PERFORMANCE_CHANGELOG.md (Full details in PERFORMANCE_CHANGELOG.md).

🔄 API جديد للعمليات (New Operations API)

  • QuranREWithMapping مع أنماط M: الوسمية ووسوم التجويد T/D تحل محل دالة sub_with_mapping القديمة (QuranREWithMapping with tagged M: patterns and T/D tajweed tags replaces the old sub_with_mapping function).
  • تتبع تدريجي واحد للخرائط وقواعد التجويد عبر جميع عمليات التحويل (One progressive tracking of mappings and tajweed rules across all conversion operations).

🧠 محرك أنماط أخطاء التلاوة (Recitation Error Pattern Engine)

  • إضافة ReciterErrPatern مع أنماط R: لكشف أخطاء التلاوة المعروفة كأنماط وسمية (Added ReciterErrPatern with R: patterns to detect known recitation mistakes as tagged patterns).
  • وسوم مسماة على جميع العمليات e/i/r/d، مع وسوم اختيارية يمكن أن تطابق فراغاً (Named tags on all ops e/i/r/d, plus optional tags that may match empty).
  • نمط الخطأ المطابق يهيمن على الأخطاء العامة في مداه فيمنع تكرار الأخطاء لنفس الموضع (A matched pattern dominates the generic errors in its span, preventing duplicate errors for the same region).
  • خيار err_tag لتحديد موضع الخطأ من وسم معين، وشروط check_group الإضافية على مجموعة الحروف (The err_tag option anchors the reported error to a chosen tag, and check_group adds custom conditions on the phoneme groups).
  • قوائم قواعد التجويد المدرجة/المستبدلة/المفقودة داخل ReciterError كـ ExplainedTajweedRule (Inserted/replaced/missing tajweed rule lists inside ReciterError as ExplainedTajweedRule).

🆕 ما الجديد في الإصدار 0.6.2 (What's New in Version 0.6.2)

  • التعارض يقع تحديداً في كلمة ضَعْفًا حيث توجد في سورتي الروم والأنفال (The conflict is specifically about ضَعْفًا, which occurs in both Surah Ar-Rum and Al-Anfal). في الروم يجوز الضم أو الفتح، أما في الأنفال فبالفتح فقط (In Ar-Rum both damma and fatha; in Al-Anfal only fatha).
  • إذا كان المدخل هو ضَعْفًا فقط دون سياق، لا يمكن استنتاج أي الموضعين (If the input is only ضَعْفًا with no context, we cannot infer which reading to apply).
  • السلوك الافتراضي: استخدام الأصل بالفتح (Default behavior: use the original with Fath) إلا إذا توفر سياق كافٍ من كلمات سابقة أو حدد المستخدم sura_idx (unless there is enough context from preceding words, or the surah is tied via sura_idx).
  • إضافة معامل sura_idx إلى دالة quran_phonetizer لاستخدام القاعدة الصحيحة عندما ترتبط قاعدة بسورة محددة (Added a sura_idx argument to quran_phonetizer to apply the correct rule when a rule is tied to a specific surah).

🆕 ما الجديد في الإصدار 0.5.1 (What's New in Version 0.5.1)

🎯 تحليل أخطاء التلاوة (Recitation Error Analysis)

  • إضافة دالة explain_error لمقارنة النص الصوتي المتوقع (المرجع) مع النص الصوتي المُتنبأ به (مثلاً من قارئ أو نموذج تعلم آلي).
  • توفير تحليل تفصيلي للأخطاء يشمل:
    • نوع الخطأ: تجويدي (tajweed)، عادي (normal)، أو حركات (tashkeel).
    • نوع الخطأ الكلامي: إدراج (insert)، حذف (delete)، أو استبدال (replace).
    • قواعد التجويد المرتبطة بالخطأ (مثل المد، القلقلة، الغنة) مع تحديد الطول المتوقع والفعلي عند الاقتضاء.
  • تمثيل النتائج باستخدام كائن ReciterError الذي يحتوي على معلومات دقيقة عن موقع الخطأ في النص العثماني والصوتي.
  • هذه الأداة مفيدة لتقييم أداء قراء القرآن، وتحليل أخطاء نماذج التعرف على الكلام، وتقديم تغذية راجعة للمتعلمين.

🆕 ما الجديد في الإصدار 0.4.0 (What's New in Version 0.4.0)

  • إضافة فئة PhoneticSearch للبحث عن نصوص صوتية في القرآن باستخدام التشابه الضبابي (Levenshtein distance) باستخدام مكتبة fuzzysearch
  • بناء فهرس مسبق للرسم الصوتي (phoneme index) لتسريع البحث بشكل كبير.
  • دعم تحديد نسبة الخطأ المسموح بها (error_ratio) للحصول على نتائج حتى مع الاختلافات الطفيفة.
  • تمثيل النتائج باستخدام PhonemesSearchSpan و PhonmesSearhResult مع معلومات دقيقة عن الموقع (السورة، الآية، الكلمة، الحرف، المؤشر الصوتي).

🛠️ بناء الفهرس (Building the Index)

  • يتم تضمين الفهرس الجاهز (ph_index.npy و ref_norm_ph.txt) داخل الحزمة، ولا يحتاج المستخدم العادي إلى بنائه.
  • للمطورين الذين يرغبون في إعادة بناء الفهرس (بعد تعديل قواعد التحويل الصوتي مثلاً)، يمكن استخدام الأمر:
    python -m ph-ndx
    
    وسيتم حفظ الملفات في مجلد quran-script داخل الحزمة.

🆕 ما الجديد في الإصدار 0.3.0 (What's New in Version 0.3.0)

📍 خرائط المواقع الجديدة (New Position Mappings)

  • أسرع مرتان في عملية إنشاء الرسم الصوتي (Faster 2x in phonetizatoin)
  • تمثيل الحروف المحذوفة ب MappingPos(pos=(x, x), deleted=True - حيث x رقم صحيح أكبر من الصفر - بدلا من None (Represent deleted characther with MappingPos(pos=(x, x), deleted=True) -where x is an integer >=0- instead of None)

🆕 ما الجديد في الإصدار 0.2.0 (What's New in Version 0.2.0)

📍 خرائط المواقع الجديدة (New Position Mappings)

  • إضافة خرائط المواقع من الرسم العثماني إلى الرسم الصوتي (Added position mappings from Uthmani script to phonetic script)
  • تتبع دقيق لتحويل كل حرف إلى موضعه الجديد (Precise tracking of character transformations)
  • دعم تمثيل الأحرف المحذوفة بقيمة None (Support for deleted characters representation with None)

📖 Quran Transcript

🔧 Installation

Install the package directly from GitHub using pip:

pip install quran-transcript

🧠 Usage Examples

🕋 Aya Object

إنشاء كائن Aya لتمثيل آية محددة واسترجاع معلوماتها

from quran_transcript import Aya

aya = Aya(1, 1)  # سورة الفاتحة، الآية 1
print(aya)

aya_info = aya.get()
print(aya_info)

🔁 Loop Through All Surahs

التنقل عبر جميع الآيات في القرآن

start_aya = Aya()
for aya in start_aya.get_ayat_after():
    aya_info = aya.get()
    # Do something with the aya info

🧮 Get Number of Verses per Surah

بناء خريطة بأرقام السور وعدد آياتها

sura_to_aya_count = {}
start_aya = Aya(1, 1)

for i in range(1, 115):  # 114 سورة في القرآن
    aya.set(i, 1)
    sura_to_aya_count[i] = aya.get().num_ayat_in_sura

print(sura_to_aya_count)

🔄 Convert Imlaey Script to Uthmani

تحويل الرسم الإملائي للرسم العثماني

from quran_transcript import search, Aya

imlaey_text = 'فأخرج به من الثمرات رزقا لكم'
results = search(
    imlaey_text,
    start_aya=Aya(2, 13),
    window=20,
    remove_tashkeel=True
)

uthmani_script = results[0].uthmani_script
print(uthmani_script)

🔤 Convert Uthmani Script to Phonetic Script

تحويل الرسم العثماني للرسم الصوتي للقرآن

from quran_transcript import Aya, search, quran_phonetizer, MoshafAttributes
import json

imlaey_text = "بسم الله الرحمن الرحيم"
results = search(
    imlaey_text,
    start_aya=Aya(1, 1),
    window=2,
    remove_tashkeel=True
)

# الحصول على الرسم العثماني
uthmani_script = results[0].uthmani_script
print(f"الرسم العثماني:\n{uthmani_script}")

# إعداد خصائص المصحف للتحويل الصوتي
moshaf = MoshafAttributes(
    rewaya="hafs",
    madd_monfasel_len=4,
    madd_mottasel_len=4,
    madd_mottasel_waqf=4,
    madd_aared_len=4,
)

# الحصول على الرسم الصوتي مع الخرائط
phonetic_script = quran_phonetizer(uthmani_script, moshaf)

print('\n' * 2)
print(f"الرسم الصوتي:\n{phonetic_script.phonemes}")
# print(f"صفات الحروف:\n{phonetic_script.sifat}")
print('\n' * 2)
print("صفات الحروف:")
for sifa in phonetic_script.sifat:
    print(json.dumps(sifa.model_dump(), ensure_ascii=False, indent=4))
    print()


# جديد: عرض خرائط المواقع
print('\n' * 2)
print("خرائط المواقع:")
for idx, (uth_char, mapping) in enumerate(zip(uthmani_script, phonetic_script.mappings)):
    if not mapping.deleted:
        # استخراج الصوت لهذا الحرف
        phoneme = phonetic_script.phonemes[mapping.pos[0]:mapping.pos[1]]
        print(f"حرف: '{uth_char}' -> صوت: '{phoneme}' (موقع: {mapping.pos})")
    else:
        print(f"حرف: '{uth_char}' -> محذوف")

📘 For more information on MoshafAttributes, refer to the Quran Dataset Documentation.

الرسم الصوتي للقرآن الكريم

📊 خرائط المواقع (Position Mappings)

خرائط المواقع توفر تتبع دقيق لمواقع الأحرف من النص العثماني الأصلي إلى النص الصوتي المحول. Position mappings provide precise tracking of character positions from original Uthmani text to converted phonetic text.

# الوصول إلى بيانات الخرائط
mappings = phonetic_script.mappings  # List[MappingPos]
phonemes = phonetic_script.phonemes  # str

# المرور على خرائط الأحرف
for idx, mapping in enumerate(mappings):
    # الحصول على امتداد الموقع
    start, end = mapping.pos  # Python-style slice notation
    if not mapping.deleted:
        # استخراج الصوت المقابل
        char_phoneme = phonemes[start:end]
        print(f"الحرف {idx} ينتقل إلى الصوت في الموقع ({start}, {end})")
    else:
        # الحرف المحذوف يبقى في الخرائط ببداية ونهاية متساويتين
        print(f"الحرف {idx} تم حذفه أثناء التحويل (pos = ({start}, {end}))")

فهم MappingPos (Understanding MappingPos)

class MappingPos:
    """خرائط المواقع لتحويلات الأحرف (Position mapping for character transformations)"""
    # `pos` خاصية تعيد (بداية، نهاية) بالطريقة البايثونية
    # (`pos` is a property returning (start, end) in Python-style slice notation)
    pos: tuple[int, int]
    tajweed_rules: list[TajweedRuleType] | None = None  # قواعد التجويد المرتبطة
    deleted: bool = False  # الحرف المحذوف يمثل بـ `MappingPos(pos=(x, x), deleted=True)` وليس `None`
                           # (a deleted character is `MappingPos(pos=(x, x), deleted=True)`, not `None`)
from quran_transcript import PhoneticSearch

# إنشاء كائن البحث (سيحمل الفهرس تلقائياً)
searcher = PhoneticSearch()

# نص صوتي للبحث (يمكن أن يكون غير دقيق)
query = "قَلِۦۦلَممممَاا"  # مثال من الاختبارات

# البحث بنسبة خطأ 10%
results = searcher.search(query, error_ratio=0.1)

# عرض النتائج
for r in results:
    print(f"سورة {r.start.sura_idx}, آية {r.start.aya_idx}")
    print(f"  من كلمة {r.start.uthmani_word_idx} حرف {r.start.uthmani_char_idx} إلى كلمة {r.end.uthmani_word_idx} حرف {r.end.uthmani_char_idx}")
    print(f"  المؤشرات الصوتية: {r.start.phonemes_idx} - {r.end.phonemes_idx}")

# استخراج النص العثماني المطابق
uthmani_text = searcher.get_uthmani_from_result(results[0])
print(f"النص العثماني: {uthmani_text}")

📦 كائنات النتائج (Result Dataclasses)

PhonemesSearchSpan

يمثل موقعاً واحداً في القرآن (بداية أو نهاية المطابقة):

  • sura_idx: رقم السورة (1-based)
  • aya_idx: رقم الآية (1-based)
  • uthmani_word_idx: فهرس الكلمة داخل الآية (0-based)
  • uthmani_char_idx: فهرس الحرف داخل الكلمة (0-based، شامل للبداية، غير شامل للنهاية)
  • phonemes_idx: فهرس المجموعة الصوتية في التسلسل الصوتي المرجعي (0-based)

PhonmesSearhResult

يحتوي على زوج من PhonemesSearchSpan للبداية والنهاية:

  • start: موقع بداية المطابقة
  • end: موقع نهاية المطابقة (غير شامل)

📖 مثال على تحليل أخطاء التلاوة (Error Analysis Example)

from quran_transcript import (
    quran_phonetizer,
    MoshafAttributes,
    ReciterError,
    explain_error,
)

# إعداد خصائص المصحف
moshaf = MoshafAttributes(
    rewaya="hafs",
    madd_monfasel_len=4,
    madd_mottasel_len=4,
    madd_mottasel_waqf=4,
    madd_aared_len=4,
)

# النص العثماني الأصلي
uthmani_text = "قَالُوٓا۟"

# نص صوتي متوقع (مرجعي)
ref_out = quran_phonetizer(uthmani_text, moshaf)
print("المرجع:", ref_out.phonemes)

# نص صوتي مُتنبأ به (به أخطاء)
predicted_text = "فكۥۥلۥۥ"
print("المتنبأ به:", predicted_text)

# تحليل الأخطاء
errors = explain_error(
    uthmani_text=uthmani_text,
    ref_ph_text=ref_out.phonemes,
    predicted_ph_text=predicted_text,
    mappings=ref_out.mappings,
)

# عرض النتائج
for err in errors:
    print("\n" + "="*50)
    print(f"الموقع في العثماني: `{uthmani_text[err.uthmani_pos[0]:err.uthmani_pos[1]]}`, {err.uthmani_pos}")
    print(f"الموقع في الصوتي: `{ref_out.phonemes[err.ph_pos[0]:err.ph_pos[1]]}`, {err.ph_pos}")
    print(f"نوع الخطأ: {err.error_type} - {err.speech_error_type}")
    print(f"المتوقع: '{err.expected_ph}' - المُتنبأ به: '{err.preditected_ph}'")
    if err.ref_tajweed_rules:
        for rule in err.ref_tajweed_rules:
            print(
                f"  قاعدة تجويد مرجعية: {rule.name.ar} ({rule.name.en}) — "
                f"ph: {rule.ph_pivot}, uth: {rule.uth_pivot}"
            )
    if err.replaced_tajweed_rules:
        for rule in err.replaced_tajweed_rules:
            print(f"  قاعدة تجويد مستبدلة: {rule.name.ar} ({rule.name.en})")
    if err.missing_tajweed_rules:
        for rule in err.missing_tajweed_rules:
            print(f"  قاعدة تجويد مفقودة: {rule.name.ar} ({rule.name.en})")

مخرجات متوقعة (Partial output):

المرجع: قَاالُۥۥ
المتنبأ به: فكۥۥلۥۥ

==================================================
الموقع في العثماني: ``, (0, 0)
الموقع في الصوتي: ``, (0, 0)
نوع الخطأ: normal - insert
المتوقع: '' - المُتنبأ به: 'ف'

==================================================
الموقع في العثماني: `قَ`, (0, 2)
الموقع في الصوتي: `قَ`, (0, 2)
نوع الخطأ: normal - replace
المتوقع: 'قَ' - المُتنبأ به: 'ك'

==================================================
الموقع في العثماني: `ا`, (2, 3)
الموقع في الصوتي: `اا`, (2, 4)
نوع الخطأ: tajweed - replace
المتوقع: 'اا' - المُتنبأ به: 'ۥۥ'
  قاعدة تجويد مرجعية: المد الطبيعي (Normal Madd) — ph: (2, 4), uth: (2, 3)

==================================================
الموقع في العثماني: `لُ`, (3, 5)
الموقع في الصوتي: `لُ`, (4, 6)
نوع الخطأ: tashkeel - delete
المتوقع: 'لُ' - المُتنبأ به: 'ل'

📦 كائنات تحليل الأخطاء (Error Analysis Dataclasses)

ReciterError

يمثل خطأ واحد في التلاوة:

  • uthmani_pos: tuple[int, int] – موقع الخطأ في النص العثماني (بداية، نهاية).
  • ph_pos: tuple[int, int] – موقع الخطأ في النص الصوتي المرجعي (بداية، نهاية).
  • error_type: Literal["tajweed", "normal", "tashkeel"] – نوع الخطأ.
  • speech_error_type: Literal["insert", "delete", "replace"] – نوع الخطأ الكلامي.
  • expected_ph: str – المقطع الصوتي المتوقع.
  • preditected_ph: str – المقطع الصوتي المُتنبأ به.
  • expected_len: int – الطول المتوقع (لأخطاء المد مثلاً)، و -1 عند عدم الانطباق (Expected length, e.g. for madd errors; -1 when not applicable).
  • predicted_len: int – الطول الفعلي، و -1 عند عدم الانطباق (Predicted length; -1 when not applicable).
  • expected_tashkeel: "fatha" | "dama" | "kasra" | "skoon" | None – الحركة الصحيحة عند خطأ حركة.
  • predicted_tashkeel: نفس القيم – الحركة المسموعة عند خطأ حركة.
  • ref_tajweed_rules: list[ExplainedTajweedRule] – قواعد التجويد المرتبطة بالمقطع المتوقع.
  • inserted_tajweed_rules, replaced_tajweed_rules, missing_tajweed_rules: list[ExplainedTajweedRule] – قواعد التجويد التي تم إدراجها أو استبدالها أو فقدانها.

📌 إذا كنت قادماً من الإصدار 0.6.x، فقد تغيّر شكل ReciterError بالكامل؛ راجع التنبيه في قسم الإصدار 0.7.1 أعلاه.

If you are upgrading from 0.6.x, ReciterError has changed completely; see the note in the 0.7.1 section above.

ExplainedTajweedRule

لقطة بيانات ثابتة وقابلة للتسلسل لقاعدة تجويد واحدة، وتحتوي على:

  • name: MultiLangText – اسم القاعدة بالعربية والإنجليزية.
  • description: MultiLangText – وصف القاعدة.
  • rule_type: TajweedRuleType – نوع القاعدة.
  • correctness: "match" | "count" | "descriptive" – طريقة تقييم القاعدة.
  • ph_pivot: tuple[int, int] – موضع القاعدة المحوري في النص الصوتي.
  • ph_deps: list[tuple[int, int]] – مواضع الحروف التابعة في النص الصوتي.
  • uth_pivot: tuple[int, int] – موضع القاعدة المحوري في النص العثماني.
  • uth_deps: list[tuple[int, int]] – مواضع الحروف التابعة في النص العثماني.
  • tag: str – الوسم المرتبط بالقاعدة، إن وجد.
  • golden_len: int – الطول الصحيح للقواعد التي تُقاس بالعدد (مثل المد)، و -1 لغيرها.

كل موضع هو (بداية، نهاية) بنصف مفتوح. القواعد الثابتة (المدرجة/المستبدلة/المفقودة) قد تحمل قيماً افتراضية مثل (-1, -1) عندما لا يكون لها موضع وقت التشغيل.

🧠 أنماط أخطاء التلاوة (Reciter Error Patterns)

ReciterErrPatern هو محرك أنماط متقدم يعمل على محاذاة مجموعات الحروف الصوتية. يستخدمه explain_error داخلياً لاكتشاف أخطاء التلاوة المعروفة، ويمكن استخدامه مباشرةً لإضافة نمط مخصص أو اختبار نمط على محاذاة جاهزة (ReciterErrPatern is an advanced pattern engine that operates on phoneme-group alignments. explain_error uses it internally to detect known recitation errors, and you can use it directly to add a custom pattern or test one against an existing alignment).

صيغة النمط (Pattern Syntax)

يبدأ النمط بـ R: ويتكوّن من وسوم متصلة:

R:<op[,name]:tag-pattern>...
الرمز المعنى
e مساواة (equal)
i إدراج (insert)
r استبدال (replace)
d حذف (delete)
  • name اسم اختياري للوسم، ويجب ألا يتكرر داخل النمط.
  • داخل الوسم: حرف حرفي، أو فئة أحرف مثل [abc]، أو .، ويمكن جعل أي ذرة اختيارية بإضافة ?.
  • ^ و$ anchors صفرية العرض، وتُكتب في بداية الوسم أو نهايته فقط.
  • لا تُدعم التعبيرات النمطية الكاملة أو lookaround؛ الصيغة مقيدة لضمان طول مجموعة متوقع.
  • الوسم الاختياري الذي يطابق فراغاً لا يستهلك أي محاذاة. هذا مفيد للتمييز بين الإدراج والاستبدال حسب وجود الحرف.
  • يتم الترميز باستخدام op + أول حرف من المجموعة: للمساواة والإدراج والاستبدال يؤخذ الحرف من المجموعة المتوقعة (المُتنبأ بها)، وللحذف من المجموعة المرجعية. لذلك يطابق النمط ما سُمع فعلاً في حالات الاستبدال، لا ما كان متوقعاً.

مثال (Example)

from quran_transcript.phonetics.error_pat import (
    PhonemesGroupsAligment,
    ReciterErrPatern,
)

err_pat = ReciterErrPatern(
    r"R:<e,t0:A><i,t1:B?>",  # A متساوية، ثم B مُدرجة اختيارياً
    err_tag="t1",
)

matches = err_pat.find_all(
    ref_ph_groups=["A"],
    pred_ph_groups=["A", "B"],
    ph_groups_align=[
        PhonemesGroupsAligment("equal", 0, 0),
        PhonemesGroupsAligment("insert", 1, 1),
    ],
    ref_group_rules=[[], []],
    ref_ph_to_uthmani=[0, 1],
)

for err in matches.errors:
    print(err.error_type, err.speech_error_type)
    print(err.uthmani_pos, err.ph_pos)

النتيجة (Output):

normal insert
(1, 1) (1, 1)

الخيارات (Options)

  • error_type: "tajweed" | "normal" | "tashkeel" | None – تجاوز نوع الخطأ المكتشف.
  • speech_error_type: "insert" | "delete" | "replace" | None – تجاوز نوع الخطأ الكلامي.
  • err_tag: اسم وسم مسمى. عند تعيينه يُبلَّغ الخطأ عن نطاق هذا الوسم فقط، وباقي النمط سياق. الافتراضي "" يعني نطاق المطابقة كاملاً.
  • check_group: قاموس من اسم وسم مسمى إلى دالة (ref_group, pred_group, rule_types) -> bool. الوسيط الثالث هو أنواع قواعد التجويد الفريدة في المقطع المرجعي. إرجاع False يرفض المطابقة. مفاتيح القاموس يجب أن تكون أسماء وسوم في النمط.
  • inserted_tajweed_rules, replaced_tajweed_rules, missing_tajweed_rules: قوائم TajweedRuleType تصف قواعد أُضيفت أو استُبدلت أو فُقدت. تُعاد كـ ExplainedTajweedRule بحقولها الثابتة فقط، مع مواقع (-1, -1) وgolden_len=-1 لأنها ليست مرتبطة بموضع وقت التشغيل.

مثال على check_group:

from quran_transcript.phonetics.tajweed_rulses import TajweedRuleType

err_pat = ReciterErrPatern(
    r"R:<e,t0:A><r,t1:C>",
    err_tag="t1",
    check_group={
        "t0": lambda ref_group, pred_group, rule_types: (
            TajweedRuleType.NORMAL_MADD in rule_types
        )
    },
)

المدخلات والنتيجة (Inputs and Result)

find_all() يأخذ:

  • ref_ph_groups وpred_ph_groups: مجموعات الحروف الصوتية المرجعية والمتوقعة.
  • ph_groups_align: قائمة PhonemesGroupsAligment(op_type, ref_idx, pred_idx).
  • ref_group_rules: قائمة قواعد التجويد لكل مجموعة مرجعية، من نوع list[list[TajweedRuleMetadata]]. يمكن تمرير قوائم فارغة إذا لم تكن بحاجة إلى قواعد.
  • ref_ph_to_uthmani: تحويل فهارس الحروف الصوتية المرجعية إلى فهارس النص العثماني، مع عنصر أخير إضافي. يمكن الحصول عليه من ref_out.mappings.ph_to_uth.

ويعيد ReciterErrPatMatches:

  • errors: قائمة ReciterError.
  • covered_alignments: مجموعة frozenset من المحاذيات التي استهلكها نمط مقبول وأنتج خطأً. استخدمها لتجاهل الأخطاء العامة التي يغطيها النمط.

المطابقات غير متداخلة، وتتبع سلوك re.finditer.

الأنماط المضمنة (Built-in Patterns)

يطبق explain_error القائمة ERR_PATERNS تلقائياً بعد المحاذاة العامة. تشمل هذه الأنماط:

  • أحكام النون الساكنة والتنوين: الإظهار، الإدغام، القلب، والإخفاء.
  • أحكام الميم الساكنة: الإظهار، الإدغام، والإخفاء.
  • الميم والنون المشددتان في الوقف العارض.
  • الإدغام الكامل.
  • الألفات السبعة.
  • التقاء الساكنين وحذف الحرف الأول.
  • همزة الوصل.
  • اجتماع همزتين.

يُرجّح النمط المطابق على الأخطاء العامة في محاذاته، ولذلك تستخدم covered_alignments لمنع تكرار الخطأ نفسه.

💡 في الاستخدام العادي استخدم explain_error؛ فهو يبني المجموعات والمحاذاة ويطبق الأنماط المضمنة. استخدم ReciterErrPatern مباشرةً لإضافة نمط مخصص أو لاختبار نمط على محاذاة جاهزة.

For normal use, prefer explain_error; it builds the groups/alignments and applies the built-in patterns. Use ReciterErrPatern directly to add a custom pattern or test one against an existing alignment.

🖼️ مثال لتفسير خطأ تلاوة (A Sample Recitation Error Explanation)

يولّد app/render_errors_html.py تقرير HTML واحداً مكتفياً بذاته من الأمثلة الموجودة في tests/test_explain_error_api.py، باستخدام quran_phonetizer ثم explain_error. يعرض التقرير:

  • النص العثماني بخط me_quran مع تظليل مواضع الأخطاء باللون الأحمر.
  • الرسم الصوتي المتوقع أسفل كل مثال.
  • بطاقات أخطاء مقروءة دون رموز صوتية خام.
  • قواعد التجويد المرجعية كشرائح قابلة للنقر.
  • زر تبديل بين العربية والإنجليزية.

جرّب المثال: افتح مثال تفسير خطأ تلاوة.

اضغط على أي قاعدة تجويد مرجعية تحت «القواعد المرجعية» لتظليل موضعها في النص العثماني باللون الأزرق، بما يشمل pivot + dependencies. اضغط على القاعدة نفسها مرة أخرى لإزالة التظليل.

Click any reference Tajweed rule under “Reference rules” to highlight its combined Uthmani span (pivot + dependencies) in light blue. Click it again to clear the highlight.

التوليد (Generating the report)

uv run app/render_errors_html.py
uv run app/render_errors_html.py --out /tmp/errors.html
uv run app/render_errors_html.py --api-file path/to/examples.py --out report.html
  • المسار الافتراضي للإخراج: app/reports/errors_report.html.
  • --api-file يقرأ ملف أمثلة آخر بنفس تنسيق tests/test_explain_error_api.py (تعيينات uthmani_text وpredicted_text، والتعليقات كعناوين).
  • --out يحدد مسار ملف HTML الناتج.
  • التقرير مكتفٍ بذاته: الخط العربي مضمّن داخل الملف، ويمكن فتحه أو مشاركته مباشرة.
  • التظليل يعتمد على CSS Custom Highlight API؛ استخدم متصفحاً حديثاً. إذا لم يكن مدعوماً يظهر تنبيه أعلى الصفحة، لكن بقية التقرير تظل قابلة للعرض.

الحروف: (43)

Phoneme Name Symbol الحرف بالعربية
hamza ء همزة
baa ب باء
taa ت تاء
thaa ث ثاء
jeem ج جيم
haa_mohmala ح حاء
khaa خ خاء
daal د دال
thaal ذ ذال
raa ر راء
zay ز زاي
seen س سين
sheen ش شين
saad ص صاد
daad ض ضاد
taa_mofakhama ط طاء
zaa_mofakhama ظ ظاء
ayn ع عين
ghyn غ غين
faa ف فاء
qaf ق قاف
kaf ك كاف
lam ل لام
meem م ميم
noon ن نون
haa ه هاء
waw و واو
yaa ي ياء
alif ا نصف مد ألف
yaa_madd ۦ نصف مد ياء
waw_madd ۥ نصف مد واوا
fatha َ فتحة
dama ُ ضمة
kasra ِ كسرة
fatha_momala ۪ فتحة ممالة
alif_momala ـ ألف ممالة
hamza_mosahala ٲ همزة مسهلة
qlqla ڇ قلقة
noon_mokhfah ں نون مخفاة
meem_mokhfah ۾ ميم مخفاة
sakt ۜ سكت
dama_mokhtalasa ؙ ضمة مختلسة (عند الروم في تأمنا)

صفات الحروف (10)

Sifat (English) Sifat (Arabic) Available Attributes (English) Available Attributes (Arabic)
hams_or_jahr الهمس أو الجهر hams, jahr همس, جهر
shidda_or_rakhawa الشدة أو الرخاوة shadeed, between, rikhw شديد, بين بين, رخو
tafkheem_or_taqeeq التفخيم أو الترقيق mofakham, moraqaq, low_mofakham مفخم, مرقق, أدنى المفخم
itbaq الإطباق monfateh, motbaq منفتح, مطبق
safeer الصفير safeer, no_safeer صفير, لا صفير
qalqla القلقلة moqalqal, not_moqalqal مقلقل, غير مقلقل
tikraar التكرار mokarar, not_mokarar مكرر, غير مكرر
tafashie التفشي motafashie, not_motafashie متفشي, غير متفشي
istitala الاستطالة mostateel, not_mostateel مستطيل, غير مستطيل
ghonna الغنة maghnoon, not_maghnoon مغنون, غير مغنون

Needs refactory

Build for Source

create a venv or a conda environment to avoid coflicts, Then

cd quran-transcript
python -m pip install -r ./

Annotation Application of annotation imlaey to uthmnai

To start server:

python -m uvicorn server:app --port 900

To start streamlit

python -m streamlit run streamlit_app

Quran Script Description

[TODO]

merge_uthmani_imlaey.py

Merging Uthmani Quran and Imlaye Quran scipts of tanzil into a single scipt (".xml" and ".json")

  • Uthmanic: without (pause marks, sajda signs, hizb signs)
  • Imlaey: without (pause marks, sajda signs, hizb signs and tatweel sign) Usage:
usage: Merge Uthmani and Imlaey Script into a single scipt [-h] [--uthmani-file UTHMANI_FILE] [--imlaey-file IMLAEY_FILE] [--output-file OUTPUT_FILE]

options:
  -h, --help            show this help message and exit
  --uthmani-file UTHMANI_FILE
                        The path to the input file "file.xml"
  --imlaey-file IMLAEY_FILE
                        The path to the input file "file.xml"
  --output-file OUTPUT_FILE
                        The path to the output file either ".json" or ".xml"

Example within the repo (json):

python merge_uthman_imlaey.py --uthmani-file quran-script/quran-uthmani-without-pause-sajda-hizb-marks.xml --imlaey-file quran-script/quran-simple-imlaey-without-puase-sajda-hizb-marks-and-tatweel.xml --output-file quran-script/quran-uthmani-imlaey.json

Example within the repo (json):

python merge_uthman_imlaey.py --uthmani-file quran-script/quran-uthmani-without-pause-sajda-hizb-marks.xml --imlaey-file quran-script/quran-simple-imlaey-without-puase-sajda-hizb-marks-and-tatweel.xml --output-file quran-script/quran-uthmani-imlaey.xml

TODO

  • quran_transcript docs
  • adding tests
  • CI/CD with github

👨‍💻 Developer Setup

Prerequisites

Install uv (fast Python package manager) by following the official guide:
https://docs.astral.sh/uv/#installation

Quick install (macOS/Linux):

curl -LsSf https://astral.sh/uv/install.sh | sh

Quick install (Windows):

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Cloning

git clone https://github.com/obadx/quran-transcript.git
cd quran-transcript

Installing Dependencies

uv sync --all-extras

Running Tests

Run all tests (as configured in pyproject.toml):

uv run pytest

Run individual test files:

uv run pytest tests/phonetics_pytest.py -v
uv run pytest tests/aya_pytest.py -vv
uv run pytest tests/test_phonemes_search_pytest.py -vv
uv run pytest tests/test_sub_with_tagged_mapping_pytest.py -vv
uv run pytest tests/test_error_pat_pytest.py -vv
uv run pytest tests/test_explain_error_pytest.py -vv

The package data (quran-script/) is linked into src/quran_transcript/ via a relative symlink:

src/quran_transcript/quran-script -> ../../quran-script/

This symlink may not work on Windows by default. To resolve this, either:

  1. Enable Developer Mode (Windows 10/11):
    Settings → Update & Security → For Developers → Enable Developer Mode.
    This allows Windows to support symlinks without elevated privileges.

  2. Manually copy the directory (no symlink needed):

    rmdir src\quran_transcript\quran-script
    xcopy /E quran-script src\quran_transcript\quran-script\
    
  3. Use mklink /D (run as Administrator):

    cd src\quran_transcript
    rmdir quran-script
    mklink /D quran-script ..\..\quran-script
    

🧪 Running Tests

The test suite includes stress tests (marked with @pytest.mark.stress) that iterate over the whole Quran and are slow.

Run the full test suite (includes stress tests):

uv run pytest

Run a quick test pass (skips stress tests):

uv run pytest --skip-stress

Run only the stress tests:

uv run pytest -m stress

Metadata

Release files for quran-transcript 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quran-transcript 0.7.1
File Size Uploaded Provenance Actions
quran_transcript-0.7.1.tar.gz 6.7 MB Without provenance Details for quran_transcript-0.7.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quran-transcript 0.7.1
File Interpreter ABI Platform Actions
quran_transcript-0.7.1-py3-none-any.whl Python 3 none any Details for quran_transcript-0.7.1-py3-none-any.whl

Total release size: 13.2 MB

Release files / quran_transcript-0.7.1.tar.gz

Download URL quran_transcript-0.7.1.tar.gz
Size 6.7 MB
Tags Source
SHA-256 checksum
How to use checksums
f73ae762a5ed482f4168057e7179cffdbe38c7db7ef40a119d7f6fee57609af3
BLAKE2b-256 checksum
How to use checksums
b9c4b8af6195d575af9d535c3cd1b36b2781e1f541a74808eeea672c5667e6da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / quran_transcript-0.7.1-py3-none-any.whl

Download URL quran_transcript-0.7.1-py3-none-any.whl
Size 6.5 MB
Tags Python 3
SHA-256 checksum
How to use checksums
86345ab94fd5dcfdeab8a8a55ecf3d9b2f9df00814ee294ad40cd91b1a8bb313
BLAKE2b-256 checksum
How to use checksums
73f225db88d61daf2abd3a1f6695f48ce1c77a80ae529380d72d5561182fae1e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for quran-transcript 0.7.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page