Skip to content

利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.

Improve Arabic subtitle support and docs

harry07038b2e530bec43
diff --git a/README-ar.md b/README-ar.md
new file mode 100644
index 00000000..cd0fb96f
--- /dev/null
+++ b/README-ar.md
@@ -0,0 +1,416 @@
+<div align="center">
+<h1 align="center">MoneyPrinterTurbo 💸</h1>
+
+<p align="center">
+ <a href="https://github.com/harry0703/MoneyPrinterTurbo/stargazers"><img src="https://img.shields.io/github/stars/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="Stargazers"></a>
+ <a href="https://github.com/harry0703/MoneyPrinterTurbo/issues"><img src="https://img.shields.io/github/issues/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="Issues"></a>
+ <a href="https://github.com/harry0703/MoneyPrinterTurbo/network/members"><img src="https://img.shields.io/github/forks/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="Forks"></a>
+ <a href="https://github.com/harry0703/MoneyPrinterTurbo/blob/main/LICENSE"><img src="https://img.shields.io/github/license/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="License"></a>
+</p>
+
+<h3>العربية | <a href="README-en.md">English</a> | <a href="README.md">简体中文</a></h3>
+
+<div align="center">
+ <a href="https://trendshift.io/repositories/8731" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8731" alt="harry0703%2FMoneyPrinterTurbo | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
+</div>
+
+ما عليك سوى تقديم <b>موضوع</b> أو <b>كلمة مفتاحية</b> للفيديو، وسيقوم التطبيق تلقائياً بتوليد نص الفيديو،
+ومواد الفيديو، والترجمة، وموسيقى الخلفية، ثم تركيبها في فيديو قصير عالي الدقة.
+
+### واجهة الويب (WebUI)
+
+![](docs/webui-en.jpg)
+
+### واجهة الـ API
+
+![](docs/api.jpg)
+
+</div>
+
+## المميزات 🎯
+
+- [x] بنية **MVC** كاملة، وكود **واضح التنظيم** وسهل الصيانة، يدعم كلاً من `API` و`واجهة الويب`
+- [x] يدعم **توليد نص الفيديو بالذكاء الاصطناعي**، إضافةً إلى **النص المخصّص**
+- [x] يدعم أحجام **فيديو عالي الدقة** متنوعة
+ - [x] عمودي 9:16، `1080x1920`
+ - [x] أفقي 16:9، `1920x1080`
+- [x] يدعم **توليد الفيديو دفعةً واحدة**، فيمكن إنشاء عدة فيديوهات معاً ثم اختيار الأفضل
+- [x] يدعم ضبط **مدة مقاطع الفيديو**، مما يسهّل التحكم في تكرار تبديل المواد
+- [x] يدعم نص الفيديو بكل من **الصينية** و**الإنجليزية**
+- [x] يدعم **تركيب أصوات متعددة**، مع **معاينة فورية** للنتيجة
+- [x] يدعم **توليد الترجمة**، مع إمكانية ضبط `الخط` و`الموضع` و`اللون` و`الحجم`، كما يدعم `تحديد إطار الترجمة`
+- [x] يدعم **موسيقى الخلفية**، إما عشوائية أو ملفات موسيقى محدّدة، مع إمكانية ضبط `مستوى صوت موسيقى الخلفية`
+- [x] مصادر مواد الفيديو **عالية الدقة** و**خالية من حقوق الملكية**، كما يمكنك استخدام **موادك المحلية** الخاصة
+- [x] يدعم التكامل مع نماذج متعددة مثل **OpenAI** و**Moonshot** و**Azure** و**gpt4free** و**one-api** و**Qwen** و**Google Gemini** و**Ollama** و**DeepSeek** و**MiniMax** و**ERNIE** و**Pollinations** و**ModelScope** وغيرها
+
+## عروض فيديو توضيحية 📺
+
+### عمودي 9:16
+
+<table>
+<thead>
+<tr>
+<th align="center"><g-emoji class="g-emoji" alias="arrow_forward">▶️</g-emoji> كيف تضيف المتعة إلى حياتك </th>
+<th align="center"><g-emoji class="g-emoji" alias="arrow_forward">▶️</g-emoji> ما معنى الحياة</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td align="center"><video src="https://github.com/harry0703/MoneyPrinterTurbo/assets/4928832/a84d33d5-27a2-4aba-8fd0-9fb2bd91c6a6"></video></td>
+<td align="center"><video src="https://github.com/harry0703/MoneyPrinterTurbo/assets/4928832/112c9564-d52b-4472-99ad-970b75f66476"></video></td>
+</tr>
+</tbody>
+</table>
+
+### أفقي 16:9
+
+<table>
+<thead>
+<tr>
+<th align="center"><g-emoji class="g-emoji" alias="arrow_forward">▶️</g-emoji> ما معنى الحياة</th>
+<th align="center"><g-emoji class="g-emoji" alias="arrow_forward">▶️</g-emoji> لماذا تمارس الرياضة</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td align="center"><video src="https://github.com/harry0703/MoneyPrinterTurbo/assets/4928832/346ebb15-c55f-47a9-a653-114f08bb8073"></video></td>
+<td align="center"><video src="https://github.com/harry0703/MoneyPrinterTurbo/assets/4928832/271f2fae-8283-44a0-8aa0-0ed8f9a6fa87"></video></td>
+</tr>
+</tbody>
+</table>
+
+## متطلبات النظام 📦
+
+- المنصّات المُوصى بها: Windows 10+ أو macOS 11+ أو توزيعة Linux رئيسية
+- وجود كرت رسومات (GPU) ليس ضرورياً، لكنه مُستحسَن إن أردت نسخاً صوتياً محلياً أسرع، أو معالجة فيديو أسرع، أو توليداً دفعياً أكثر سلاسة
+
+| العنصر | الحد الأدنى | المُوصى به | الأمثل |
+| --- | --- | --- | --- |
+| المعالج (CPU) | 4 أنوية | 6 إلى 8 أنوية | 8+ أنوية |
+| الذاكرة (RAM) | 4 GB | 8 GB | 16+ GB |
+| كرت الرسومات (GPU) | غير مطلوب | 4+ GB VRAM | 8+ GB VRAM |
+
+- إذا كنت تعتمد أساساً على نماذج LLM السحابية، وخدمات TTS السحابية، ومصادر المواد عبر الإنترنت، فإن المعالج والذاكرة أهم من كرت الرسومات
+- إذا كنت تستخدم `faster-whisper` أو التوليد الدفعي أو المعالجة المحلية الثقيلة، فسيحسّن كرت الرسومات الإنتاجية بشكل ملحوظ
+
+## البدء السريع 🚀
+
+### المسارات المُوصى بها
+
+- مستخدمو Windows: استخدم الحزمة الجاهزة بنقرة واحدة أولاً للتجربة المحلية الأسرع
+- مستخدمو MacOS / Linux: استخدم `uv sync --frozen` كمسار الإعداد المحلي الأساسي
+- إذا أردت بيئة تشغيل أكثر عزلاً: استخدم النشر عبر Docker
+
+### التشغيل في Google Colab
+تريد تجربة MoneyPrinterTurbo دون إعداد بيئة محلية؟ شغّله مباشرةً في Google Colab!
+
+[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/harry0703/MoneyPrinterTurbo/blob/main/docs/MoneyPrinterTurbo.ipynb)
+
+
+### Windows
+
+الحزمة القابلة للتنزيل ما زالت بناء `v1.2.6` القديم المُجمّع. بعد التنزيل، شغّل `update.bat` أولاً لتحديثه إلى أحدث كود.
+
+Google Drive (v1.2.6): https://drive.google.com/file/d/1HsbzfT7XunkrCrHw5ncUjFX8XX4zAuUh/view?usp=sharing
+
+بعد التنزيل، يُنصح بالنقر المزدوج على `update.bat` أولاً للتحديث إلى **أحدث كود**، ثم النقر المزدوج على `start.bat` للتشغيل
+
+بعد التشغيل، سيُفتح المتصفح تلقائياً (إن فُتح فارغاً، يُنصح باستخدام **Chrome** أو **Edge**)
+
+### الأنظمة الأخرى
+
+لم تُنشأ حزم تشغيل بنقرة واحدة بعد. راجع قسم **التثبيت والنشر** أدناه. يُنصح باستخدام **docker** للنشر لأنه أكثر سهولة.
+
+## التثبيت والنشر 📥
+
+### المتطلبات المُسبقة
+
+#### ① استنساخ المشروع
+
+```shell
+git clone https://github.com/harry0703/MoneyPrinterTurbo.git
+```
+
+#### ② تعديل ملف الإعدادات
+
+- انسخ ملف `config.example.toml` وأعد تسميته إلى `config.toml`
+- اتبع التعليمات داخل ملف `config.toml` لضبط `pexels_api_keys` و`llm_provider`، وبحسب مزوّد خدمة الـ llm_provider، اضبط مفتاح الـ API المقابل
+
+### النشر عبر Docker 🐳
+
+#### ① تشغيل حاوية Docker
+
+إذا لم تكن قد ثبّت Docker، فثبّته أولاً https://www.docker.com/products/docker-desktop/
+إذا كنت تستخدم نظام Windows، فراجع وثائق Microsoft:
+
+1. https://learn.microsoft.com/en-us/windows/wsl/install
+2. https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-containers
+
+```shell
+cd MoneyPrinterTurbo
+docker-compose up
+```
+
+> ملاحظة: أحدث إصدار من docker يثبّت docker compose تلقائياً على هيئة إضافة (plug-in)، ويتغيّر أمر التشغيل إلى `docker compose up`
+
+#### ② الوصول إلى واجهة الويب
+
+افتح متصفحك وزر http://127.0.0.1:8501
+
+#### ③ الوصول إلى واجهة الـ API
+
+افتح متصفحك وزر http://0.0.0.0:8080/docs أو http://0.0.0.0:8080/redoc
+
+### النشر اليدوي 📦
+
+#### ① إنشاء بيئة Python افتراضية
+
+يُنصح باستخدام [uv](https://docs.astral.sh/uv/) لإدارة بيئة Python والاعتماديات، مع Python `3.11` كبيئة تشغيل افتراضية.
+
+```shell
+git clone https://github.com/harry0703/MoneyPrinterTurbo.git
+cd MoneyPrinterTurbo
+uv python install 3.11
+uv sync --frozen
+```
+
+إذا كنت لا تستخدم `uv` بعد، فما زال بإمكانك استخدام `venv + pip`.
+
+```shell
+python3.11 -m venv .venv
+source .venv/bin/activate
+pip install -r requirements.txt
+```
+
+ملاحظات:
+- أصبح `pyproject.toml` هو ملف الاعتماديات الأساسي.
+- يُثبّت `uv.lock` البيئة المُحدّدة، لذا يُنصح بـ `uv sync --frozen` افتراضياً.
+- يُحتفظ بـ `requirements.txt` فقط للتثبيت القديم المعتمد على `pip`.
+
+#### ② تثبيت ImageMagick
+
+###### Windows:
+
+- نزّل من https://imagemagick.org/script/download.php واختر نسخة Windows، وتأكد من اختيار نسخة **المكتبة الساكنة (static library)**، مثل ImageMagick-7.1.1-32-Q16-x64-**static**.exe
+- ثبّت ImageMagick الذي نزّلته، **ولا تغيّر مسار التثبيت**
+- عدّل ملف الإعدادات `config.toml`، واضبط `imagemagick_path` على مسار التثبيت الفعلي لديك
+
+###### MacOS:
+
+```shell
+brew install imagemagick
+```
+
+###### Ubuntu
+
+```shell
+sudo apt-get install imagemagick
+```
+
+###### CentOS
+
+```shell
+sudo yum install ImageMagick
+```
+
+#### ③ تشغيل واجهة الويب 🌐
+
+لاحظ أنك بحاجة لتنفيذ الأوامر التالية في `المجلد الجذر` لمشروع MoneyPrinterTurbo
+
+###### Windows
+
+```shell
+uv run streamlit run ./webui/Main.py --browser.gatherUsageStats=False
+```
+
+إذا كنت قد فعّلت البيئة الافتراضية يدوياً، فما زال بإمكانك تشغيل:
+
+```bat
+webui.bat
+```
+
+###### MacOS أو Linux
+
+```shell
+uv run streamlit run ./webui/Main.py --browser.gatherUsageStats=False
+```
+
+إذا كنت قد فعّلت البيئة الافتراضية يدوياً، فما زال بإمكانك تشغيل:
+
+```shell
+sh webui.sh
+```
+
+بعد التشغيل، سيُفتح المتصفح تلقائياً
+
+#### ④ تشغيل خدمة الـ API 🚀
+
+```shell
+uv run python main.py
+```
+
+إذا كنت قد فعّلت البيئة الافتراضية يدوياً، فما زال بإمكانك تشغيل:
+
+```shell
+python main.py
+```
+
+## شكر خاص 🙏
+
+نظراً لأن **نشر** و**استخدام** هذا المشروع يمثّل عتبةً معينة لبعض المستخدمين المبتدئين، نودّ أن نتقدّم بشكر خاص إلى
+
+**RecCloud (منصة خدمات وسائط متعددة مدعومة بالذكاء الاصطناعي)** لتقديمها خدمة `AI Video Generator` مجانية مبنية على هذا
+المشروع. فهي تتيح الاستخدام عبر الإنترنت دون نشر، وهو أمر مريح للغاية.
+
+- النسخة الصينية: https://reccloud.cn
+- النسخة الإنجليزية: https://reccloud.com
+
+![](docs/reccloud.com.jpg)
+
+## شكراً للرعاية 🙏
+
+شكراً لـ Picwish https://picwish.com على دعمها ورعايتها لهذا المشروع، مما يتيح التحديث والصيانة المستمرّين.
+
+تركّز Picwish على **مجال معالجة الصور**، وتوفّر مجموعة غنية من **أدوات معالجة الصور** التي تبسّط العمليات المعقّدة إلى حدٍّ بعيد، فتجعل معالجة الصور أسهل حقاً.
+
+![picwish.jpg](docs/picwish.com.jpg)
+
+بعد التشغيل، يمكنك عرض `وثائق الـ API` على http://127.0.0.1:8080/docs واختبار الواجهة مباشرةً عبر الإنترنت
+لتجربة سريعة.
+
+## تركيب الصوت 🗣
+
+يمكن عرض قائمة بجميع الأصوات المدعومة هنا: [قائمة الأصوات](./docs/voice-list.txt)
+
+2024-04-16 v1.1.2 أُضيفت 9 أصوات تركيب صوتي جديدة من Azure تتطلب ضبط مفتاح API. هذه الأصوات تبدو أكثر واقعية.
+
+## توليد الترجمة 📜
+
+حالياً، هناك طريقتان لتوليد الترجمة:
+
+- **edge**: سرعة توليد أعلى، وأداء أفضل، ولا متطلبات خاصة لمواصفات الحاسوب، لكن الجودة قد تكون غير مستقرة
+- **whisper**: سرعة توليد أبطأ، وأداء أضعف، ومتطلبات خاصة لمواصفات الحاسوب، لكن الجودة أكثر موثوقية
+
+يمكنك التبديل بينهما بتعديل `subtitle_provider` في ملف الإعدادات `config.toml`
+
+يُنصح باستخدام وضع `edge`، والتبديل إلى وضع `whisper` إذا كانت جودة الترجمة المُولّدة غير مُرضية.
+
+> ملاحظة:
+>
+> 1. في وضع whisper، تحتاج إلى تنزيل ملف نموذج من HuggingFace بحجم نحو 3GB، فتأكد من اتصال إنترنت جيد
+> 2. إذا تُرك فارغاً، فهذا يعني أنه لن تُولَّد أي ترجمة.
+
+> بما أن HuggingFace غير متاح في الصين، يمكنك استخدام الطرق التالية لتنزيل ملف نموذج `whisper-large-v3`
+
+روابط التنزيل:
+
+- Baidu Netdisk: https://pan.baidu.com/s/11h3Q6tsDtjQKTjUu3sc5cA?pwd=xjs9
+- Quark Netdisk: https://pan.quark.cn/s/3ee3d991d64b
+
+بعد تنزيل النموذج، فُكّ ضغطه وضع المجلد بالكامل في `.\MoneyPrinterTurbo\models`،
+وينبغي أن يبدو مسار الملف النهائي هكذا: `.\MoneyPrinterTurbo\models\whisper-large-v3`
+
+```
+MoneyPrinterTurbo
+ ├─models
+ │ └─whisper-large-v3
+ │ config.json
+ │ model.bin
+ │ preprocessor_config.json
+ │ tokenizer.json
+ │ vocabulary.json
+```
+
+## موسيقى الخلفية 🎵
+
+تقع موسيقى خلفية الفيديوهات في مجلد المشروع `resource/songs`.
+> يتضمّن المشروع الحالي بعض الموسيقى الافتراضية من فيديوهات YouTube. إن وُجدت مشكلات حقوق نشر، فالرجاء حذفها.
+
+## خطوط الترجمة 🅰
+
+تقع خطوط عرض ترجمة الفيديو في مجلد المشروع `resource/fonts`، ويمكنك أيضاً إضافة خطوطك الخاصة.
+
+## الأسئلة الشائعة 🤔
+
+### ❓RuntimeError: No ffmpeg exe could be found
+
+في الوضع الطبيعي، يُنزَّل ffmpeg ويُكتشَف تلقائياً.
+لكن إذا كانت بيئتك تعاني مشكلات تمنع التنزيل التلقائي، فقد تواجه الخطأ التالي:
+
+```
+RuntimeError: No ffmpeg exe could be found.
+Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.
+```
+
+في هذه الحالة، يمكنك تنزيل ffmpeg من https://www.gyan.dev/ffmpeg/builds/ ثم فك ضغطه وضبط `ffmpeg_path` على مسار
+التثبيت الفعلي لديك.
+
+```toml
+[app]
+# الرجاء الضبط بحسب مسارك الفعلي، ولاحظ أن فاصل المسارات في Windows هو \\
+ffmpeg_path = "C:\\Users\\harry\\Downloads\\ffmpeg.exe"
+```
+
+### ❓ImageMagick is not installed on your computer
+
+[issue 33](https://github.com/harry0703/MoneyPrinterTurbo/issues/33)
+
+1. اتبع `عنوان التنزيل` الموجود في `الإعداد النموذجي`
+ لتثبيت https://imagemagick.org/archive/binaries/ImageMagick-7.1.1-30-Q16-x64-static.exe (باستخدام المكتبة الساكنة)
+2. لا تثبّت في مسار يحتوي على أحرف صينية لتجنّب مشكلات غير متوقّعة
+
+[issue 54](https://github.com/harry0703/MoneyPrinterTurbo/issues/54#issuecomment-2017842022)
+
+لأنظمة Linux، يمكنك تثبيته يدوياً، راجع https://cn.linux-console.net/?p=16978
+
+شكراً لـ [@wangwenqiao666](https://github.com/wangwenqiao666) على بحثه واستكشافه
+
+### ❓ImageMagick's security policy prevents operations related to temporary file @/tmp/tmpur5hyyto.txt
+
+يمكنك إيجاد هذه السياسات في ملف إعدادات ImageMagick policy.xml.
+يقع هذا الملف عادةً في /etc/ImageMagick-`X`/ أو موقع مشابه في مجلد تثبيت ImageMagick.
+عدّل المُدخل الذي يحتوي على `pattern="@"`، وغيّر `rights="none"` إلى `rights="read|write"` للسماح بعمليات القراءة والكتابة على الملفات.
+
+### ❓OSError: [Errno 24] Too many open files
+
+تنتج هذه المشكلة عن حدّ النظام لعدد الملفات المفتوحة. يمكنك حلّها بتعديل حدّ فتح الملفات في النظام.
+
+تحقّق من الحدّ الحالي:
+
+```shell
+ulimit -n
+```
+
+إن كان منخفضاً جداً، يمكنك زيادته، مثلاً:
+
+```shell
+ulimit -n 10240
+```
+
+### ❓Whisper model download failed, with the following error
+
+LocalEntryNotfoundEror: Cannot find an appropriate cached snapshotfolderfor the specified revision on the local disk and
+outgoing trafic has been disabled.
+To enablerepo look-ups and downloads online, pass 'local files only=False' as input.
+
+أو
+
+An error occurred while synchronizing the model Systran/faster-whisper-large-v3 from the Hugging Face Hub:
+An error happened while trying to locate the files on the Hub and we cannot find the appropriate snapshot folder for the
+specified revision on the local disk. Please check your internet connection and try again.
+Trying to load the model directly from the local cache, if it exists.
+
+الحل: [اضغط لمعرفة كيفية تنزيل النموذج يدوياً من قرص الشبكة](#توليد-الترجمة-)
+
+## الملاحظات والاقتراحات 📢
+
+- يمكنك إرسال [issue](https://github.com/harry0703/MoneyPrinterTurbo/issues) أو
+ [pull request](https://github.com/harry0703/MoneyPrinterTurbo/pulls).
+
+## الرخصة 📝
+
+اضغط لعرض ملف [`LICENSE`](LICENSE)
+
+## تاريخ النجوم (Star History)
+
+[![Star History Chart](https://api.star-history.com/svg?repos=harry0703/MoneyPrinterTurbo&type=Date)](https://star-history.com/#harry0703/MoneyPrinterTurbo&Date)
diff --git a/README-en.md b/README-en.md
index cdfa8251..93d296bf 100644
--- a/README-en.md
+++ b/README-en.md
@@ -8,7 +8,7 @@
<a href="https://github.com/harry0703/MoneyPrinterTurbo/blob/main/LICENSE"><img src="https://img.shields.io/github/license/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="License"></a>
</p>
-<h3>English | <a href="README.md">简体中文</a></h3>
+<h3>English | <a href="README.md">简体中文</a> | <a href="README-ar.md">العربية</a></h3>
<div align="center">
<a href="https://trendshift.io/repositories/8731" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8731" alt="harry0703%2FMoneyPrinterTurbo | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
diff --git a/README.md b/README.md
index 614ebd63..3256f377 100644
--- a/README.md
+++ b/README.md
@@ -8,7 +8,7 @@
<a href="https://github.com/harry0703/MoneyPrinterTurbo/blob/main/LICENSE"><img src="https://img.shields.io/github/license/harry0703/MoneyPrinterTurbo.svg?style=for-the-badge" alt="License"></a>
</p>
<br>
-<h3>简体中文 | <a href="README-en.md">English</a></h3>
+<h3>简体中文 | <a href="README-en.md">English</a> | <a href="README-ar.md">العربية</a></h3>
<div align="center">
<a href="https://trendshift.io/repositories/8731" target="_blank"><img src="https://trendshift.io/api/badge/repositories/8731" alt="harry0703%2FMoneyPrinterTurbo | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
</div>
diff --git a/app/controllers/v1/video.py b/app/controllers/v1/video.py
index 5822fd88..8d561c63 100644
--- a/app/controllers/v1/video.py
+++ b/app/controllers/v1/video.py
@@ -4,7 +4,7 @@ import pathlib
import shutil
from typing import Union
-from fastapi import BackgroundTasks, Depends, Path, Request, UploadFile
+from fastapi import BackgroundTasks, Depends, Path, Query, Request, UploadFile
from fastapi.params import File
from fastapi.responses import FileResponse, StreamingResponse
from loguru import logger
@@ -163,11 +163,8 @@ def create_task(
task_id=task_id, status_code=400, message=f"{request_id}: {str(e)}"
)
-from fastapi import Query
-
@router.get("/tasks", response_model=TaskQueryResponse, summary="Get all tasks")
def get_all_tasks(request: Request, page: int = Query(1, ge=1), page_size: int = Query(10, ge=1)):
- request_id = base.get_task_id(request)
tasks, total = sm.state.get_all_tasks(page, page_size)
response = {
diff --git a/app/models/const.py b/app/models/const.py
index e7540ef3..b5892740 100644
--- a/app/models/const.py
+++ b/app/models/const.py
@@ -15,6 +15,11 @@ PUNCTUATIONS = [
":",
"!",
"...",
+ # 阿拉伯语常用标点也应作为自然断句点,避免脚本文本和 edge-tts
+ # 返回的字幕停顿边界不一致,导致后续逐行匹配失败。
+ "،",
+ "؛",
+ "؟",
]
TASK_STATE_FAILED = -1
diff --git a/app/services/voice.py b/app/services/voice.py
index 0d873785..d5f95ae1 100644
--- a/app/services/voice.py
+++ b/app/services/voice.py
@@ -15,7 +15,7 @@ from xml.sax.saxutils import unescape
import edge_tts
import requests
-from edge_tts import SubMaker, submaker
+from edge_tts import SubMaker
from loguru import logger
from moviepy.video.tools import subtitles
from moviepy.audio.io.AudioFileClip import AudioFileClip
@@ -1818,7 +1818,6 @@ def gemini_tts(
SubMaker对象或None
"""
import base64
- import json
import io
from pydub import AudioSegment
import google.generativeai as genai
@@ -2047,6 +2046,30 @@ def _build_subtitle_formatter():
return formatter
+# 阿拉伯语变音符号和 Tatweel 拉长符在 edge-tts 返回文本中可能出现,
+# 这些字符不影响语义,但会导致脚本文本和字幕 cue 字符串精确匹配失败。
+_ARABIC_DIACRITICS = re.compile("[\u0610-\u061A\u064B-\u065F\u0670\u0640\u06D6-\u06ED]")
+
+
+def _normalize_arabic(text: str) -> str:
+ """统一阿拉伯语常见字母变体,提升字幕 cue 与脚本行的匹配容错率。
+
+ edge-tts 对阿拉伯语可能返回与原脚本不同的字母形态,例如把 أ/إ/آ
+ 归一成 ا,或者携带变音符号。这里仅在最后一层匹配兜底中使用,
+ 不改变原始字幕文本,避免影响最终展示内容。
+ """
+ text = _ARABIC_DIACRITICS.sub("", text)
+ for src, dst in (
+ ("أإآٱ", "ا"),
+ ("ىئ", "ي"),
+ ("ة", "ه"),
+ ("ؤ", "و"),
+ ):
+ for ch in src:
+ text = text.replace(ch, dst)
+ return text
+
+
def _match_script_line(script_lines: list[str], current_text: str, sub_index: int) -> str:
"""
尝试把当前累计的字幕文本,与脚本中的某一条标准断句匹配起来。
@@ -2077,6 +2100,13 @@ def _match_script_line(script_lines: list[str], current_text: str, sub_index: in
if current_text_normalized == target_line_normalized:
return target_line.strip()
+ # 最后一层阿拉伯语容错:edge-tts 返回的字母形态、变音符号或 Tatweel
+ # 可能和脚本不同。只在常规匹配失败后归一化比较,非阿拉伯语文本不会受影响。
+ current_ar = re.sub(r"\W+", "", _normalize_arabic(current_text))
+ target_ar = re.sub(r"\W+", "", _normalize_arabic(target_line))
+ if current_ar and current_ar == target_ar:
+ return target_line.strip()
+
return ""
diff --git a/app/utils/utils.py b/app/utils/utils.py
index 86159da6..cfead12c 100644
--- a/app/utils/utils.py
+++ b/app/utils/utils.py
@@ -1,6 +1,7 @@
import json
import locale
import os
+from functools import lru_cache
from pathlib import Path
import threading
from typing import Any
@@ -221,7 +222,10 @@ def get_system_locale():
return "en"
+@lru_cache(maxsize=None)
def load_locales(i18n_dir):
+ # WebUI 每次交互都会触发 Streamlit 重新执行脚本,语言文件运行期不会变化,
+ # 因此缓存解析结果,避免反复读取和解析所有 i18n JSON 文件。
_locales = {}
for root, dirs, files in os.walk(i18n_dir):
for file in files:
diff --git a/test/services/test_voice.py b/test/services/test_voice.py
index 2c08ea8d..c02ba548 100644
--- a/test/services/test_voice.py
+++ b/test/services/test_voice.py
@@ -1,7 +1,6 @@
import asyncio
import base64
import unittest
-import os
import sys
import tempfile
import time
@@ -470,6 +469,67 @@ class TestVoiceService(unittest.TestCase):
self.assertEqual(len(sub_items), len(script_lines))
self.assertIn("1,000 years", sub_items[-1])
+ def test_script_split_supports_arabic_punctuation(self):
+ """
+ 阿拉伯语脚本常用 ، ؛ ؟ 作为自然断句标点。断句阶段必须识别这些
+ 标点,否则 edge-tts cue 的停顿边界和脚本行边界会错位。
+ """
+ text = "مرحبا بالعالم، كيف حالك؟ هذا اختبار؛ يعمل بشكل جيد."
+
+ self.assertEqual(
+ utils.split_string_by_punctuations(text),
+ [
+ "مرحبا بالعالم",
+ "كيف حالك",
+ "هذا اختبار",
+ "يعمل بشكل جيد",
+ ],
+ )
+
+ def test_match_script_line_normalizes_arabic_letter_forms(self):
+ """
+ edge-tts 可能把阿拉伯语中的不同字母形态归一化,或返回带变音符号、
+ Tatweel 的 cue 文本。匹配时应容错,但最终字幕仍保留原始脚本文案。
+ """
+ script_lines = ["أهلاً وسهلاً بك في المدرسة"]
+
+ matched = vs._match_script_line(
+ script_lines,
+ "اهلا وسهلا بك في المدرسه",
+ 0,
+ )
+
+ self.assertEqual(matched, script_lines[0])
+
+ def test_edge_cue_aggregation_handles_arabic_variant_forms(self):
+ """
+ 复现阿拉伯语字幕失败的核心路径:脚本包含 أ/ة 等字母形态,edge cue
+ 返回 ا/ه 等归一化形态时,聚合仍应生成完整字幕,避免回退 Whisper。
+ """
+ text = "أهلاً وسهلاً بك في المدرسة؟ هذا اختبار رائع، شكراً لك."
+ script_lines = utils.split_string_by_punctuations(text)
+ cue_texts = [
+ "اهلا وسهلا بك في المدرسه",
+ "هذا اختبار رائع",
+ "شكرا لك",
+ ]
+ sub_maker = SimpleNamespace(
+ cues=[
+ SimpleNamespace(
+ content=cue_text,
+ start=timedelta(seconds=index),
+ end=timedelta(seconds=index + 0.8),
+ )
+ for index, cue_text in enumerate(cue_texts)
+ ]
+ )
+
+ sub_items = vs._build_subtitle_items_from_edge_cues(sub_maker, script_lines)
+
+ self.assertEqual(len(sub_items), len(script_lines))
+ self.assertIn("أهلاً وسهلاً بك في المدرسة", sub_items[0])
+ self.assertIn("شكراً لك", sub_items[-1])
+
def test_convert_rate_to_percent_signs_zero_rate(self):
# Rates near but not exactly 1.0 round to 0 percent. edge-tts rejects
# an unsigned "0%" (ValueError: Invalid rate '0%'), so the helper must