Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions arabic-voice-generation-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# تطبيق توليدي للأصوات العربية

تطبيق بسيط وسريع لتحويل النص العربي إلى كلام باستخدام تقنيات مفتوحة المصدر.

## الميزات

- 🗣️ تحويل النص العربي إلى كلام بجودة عالية
- 🌐 واجهة مستخدم تفاعلية سهلة الاستخدام
- ⚡ سريع وفعال في التوليد
- 📦 يعتمد على مكتبات مفتوحة المصدر بالكامل
- 🎛️ إمكانية تعديل سرعة القراءة

## المتطلبات

- Python 3.7+
- مكتبات Python المذكورة في ملف `requirements.txt`

## التثبيت

1. تثبيت المكتبات المطلوبة:
```bash
pip install -r requirements.txt
```

2. تشغيل التطبيق:
```bash
python app.py
```

3. فتح المتصفح على العنوان: http://localhost:7860

## الاستخدام

1. أدخل النص العربي في مربع النص
2. اضبط سرعة القراءة حسب الرغبة
3. انقر على زر "تحويل إلى كلام"
4. استمع إلى الصوت المُوَلَّد أو نزّله

## التقنيات المستخدمة

- **SpeechBrain**: إطار عمل مفتوح المصدر للتعلم العميق في معالجة الكلام
- **Tacotron2**: نموذج توليدي للكلام متقدم
- **HIFIGAN**: نموذج لتوليد الصوت عالي الجودة
- **Gradio**: لإنشاء واجهة المستخدم التفاعلية

## التخصيص

يمكنك تعديل النموذج لإضافة:
- أصوات مختلفة
- لهجات عربية متنوعة
- تعديلات على سرعة القراءة والطبقة الصوتية
85 changes: 85 additions & 0 deletions arabic-voice-generation-app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import gradio as gr
import numpy as np
from tts_model import ArabicTTS
import os

# تهيئة نموذج تحويل النص إلى كلام
tts = ArabicTTS()

def generate_speech(text, speed=1.0):
"""
توليد الصوت من النص العربي

Args:
text (str): النص العربي
speed (float): سرعة القراءة (0.5-2.0)

Returns:
tuple: (معدل العينة, الصوت المُوَلَّد)
"""
if not text.strip():
return None, "الرجاء إدخال نص للتحويل"

# توليد الصوت
audio = tts.text_to_speech(text)

if audio is not None:
# تعديل سرعة القراءة إذا لزم الأمر
if speed != 1.0:
# يمكن إضافة تعديل السرعة هنا
pass

# حفظ الصوت مؤقتًا
temp_filename = "temp_output.wav"
tts.save_audio(audio, temp_filename)

# إرجاع الصوت للواجهة
return (22050, audio), None
else:
return None, "حدث خطأ في توليد الصوت"

# إنشاء واجهة المستخدم
with gr.Blocks(title="تطبيق توليدي للأصوات العربية") as demo:
gr.Markdown("# 🗣️ تطبيق توليدي للأصوات العربية")
gr.Markdown("تحويل النص العربي إلى كلام باستخدام تقنيات مفتوحة المصدر")

with gr.Row():
with gr.Column():
text_input = gr.Textbox(
label="أدخل النص العربي",
placeholder="اكتب النص الذي تريد تحويله إلى كلام...",
lines=5
)
speed_slider = gr.Slider(
minimum=0.5,
maximum=2.0,
value=1.0,
label="سرعة القراءة"
)
generate_btn = gr.Button("تحويل إلى كلام", variant="primary")

with gr.Column():
audio_output = gr.Audio(label="الصوت المُوَلَّد")
error_output = gr.Textbox(label="رسائل الخطأ", interactive=False)

generate_btn.click(
fn=generate_speech,
inputs=[text_input, speed_slider],
outputs=[audio_output, error_output]
)

gr.Markdown("### أمثلة للنصوص العربية:")
gr.Examples(
examples=[
"السلام عليكم ورحمة الله وبركاته",
"مرحباً بك في تطبيق تحويل النص إلى كلام",
"هذا التطبيق يستخدم تقنيات مفتوحة المصدر",
"يمكنك كتابة أي نص عربي وسيتم تحويله إلى كلام",
"نأمل أن تجد هذا التطبيق مفيداً"
],
inputs=text_input
)

# تشغيل التطبيق
if __name__ == "__main__":
demo.launch(server_name="0.0.0.0", server_port=7860)
17 changes: 17 additions & 0 deletions arabic-voice-generation-app/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# إعدادات الصوت
AUDIO_SAMPLE_RATE = 22050
AUDIO_CHANNELS = 1

# إعدادات النموذج
MODEL_CONFIG = {
"g2p_model": "speechbrain/tts_models/arabic-tacotron2-collab",
"tts_model": "speechbrain/tts_models/arabic-tacotron2-collab",
"vocoder_model": "speechbrain/tts_models/arabic-hifigan-collab"
}

# إعدادات الواجهة
INTERFACE_CONFIG = {
"title": "تطبيق توليدي للأصوات العربية",
"server_name": "0.0.0.0",
"server_port": 7860
}
9 changes: 9 additions & 0 deletions arabic-voice-generation-app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
torch>=1.13.0
torchaudio>=0.13.0
transformers>=4.21.0
speechbrain>=0.5.12
librosa>=0.9.2
soundfile>=0.10.3
numpy>=1.21.0
gradio>=3.24.1
huggingface_hub>=0.12.0
71 changes: 71 additions & 0 deletions arabic-voice-generation-app/tts_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import torch
import torchaudio
from speechbrain.inference.text import GraphemeToPhoneme
from speechbrain.inference.TTS import Tacotron2
from speechbrain.inference.vocoders import HIFIGAN
import numpy as np
import librosa

class ArabicTTS:
def __init__(self):
"""تهيئة نموذج تحويل النص إلى كلام للغة العربية"""
# تحميل نموذج تحويل الحروف إلى أصوات (Grapheme-to-Phoneme)
self.g2p = GraphemeToPhoneme.from_hparams(
"speechbrain/tts_models/arabic-tacotron2-collab",
savedir="pretrained_models/g2p"
)

# تحميل نموذج Tacotron2 للغة العربية
self.tts_model = Tacotron2.from_hparams(
"speechbrain/tts_models/arabic-tacotron2-collab",
savedir="pretrained_models/tts"
)

# تحميل نموذج HIFIGAN لتوليد الصوت عالي الجودة
self.vocoder = HIFIGAN.from_hparams(
"speechbrain/tts_models/arabic-hifigan-collab",
savedir="pretrained_models/vocoder"
)

def text_to_speech(self, text):
"""
تحويل النص العربي إلى كلام

Args:
text (str): النص العربي المراد تحويله

Returns:
numpy.ndarray: الصوت المُوَلَّد
"""
try:
# تحويل النص إلى صوتيفات (Phonemes)
phonemes = self.g2p.g2p(text)
print(f"النصوص الصوتية: {phonemes}")

# إنشاء التمثيل الطيفي للصوت
mel_spec, _, _ = self.tts_model.encode_text(phonemes)

# تحويل التمثيل الطيفي إلى صوت باستخدام HIFIGAN
waveform = self.vocoder.decode_batch(mel_spec)

# تحويل المصفوفة إلى مصفوفة numpy
audio = waveform.squeeze().cpu().numpy()

return audio
except Exception as e:
print(f"خطأ في توليد الصوت: {str(e)}")
return None

def save_audio(self, audio, filename, sample_rate=22050):
"""
حفظ الصوت المُوَلَّد في ملف

Args:
audio (numpy.ndarray): الصوت المُوَلَّد
filename (str): اسم الملف
sample_rate (int): معدل العينة
"""
if audio is not None:
# حفظ الصوت بصيغة WAV
torchaudio.save(filename, torch.tensor(audio).unsqueeze(0), sample_rate)
print(f"تم حفظ الصوت في: {filename}")
39 changes: 39 additions & 0 deletions arabic-voice-generation-app/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re
import os

def preprocess_arabic_text(text):
"""
معالجة النص العربي قبل التحويل إلى كلام

Args:
text (str): النص العربي الأصلي

Returns:
str: النص المُعالج
"""
# إزالة المسافات الزائدة
text = re.sub(r'\s+', ' ', text).strip()

# معالجة الأرقام العربية
arabic_numbers = {
'٠': '0', '١': '1', '٢': '2', '٣': '3', '٤': '4',
'٥': '5', '٦': '6', '٧': '7', '٨': '8', '٩': '9'
}

for arabic, english in arabic_numbers.items():
text = text.replace(arabic, english)

return text

def check_model_files():
"""التحقق من وجود ملفات النماذج المطلوبة"""
required_dirs = [
"pretrained_models/g2p",
"pretrained_models/tts",
"pretrained_models/vocoder"
]

for directory in required_dirs:
if not os.path.exists(directory):
os.makedirs(directory)
print(f"تم إنشاء المجلد: {directory}")
2 changes: 1 addition & 1 deletion config/repolinter-ruleset.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
},
"policyInfo": "GitHub requires a CODEOWNERS file in all projects. This enables GitHub to contact the maintainers in the event it is necessary.",
"policyUrl": "https://github.com/github/open-source/blob/main/policies/release.md"
},
}
},
"formatOptions": {
"disclaimer": "🤖*This issue was automatically generated by [repolinter-action](https://github.com/newrelic/repolinter-action), developed by the Open Source and Developer Advocacy team at New Relic.*"
Expand Down
23 changes: 23 additions & 0 deletions config/text-summarizer-eval.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Text Summarizer
description: Summarizes input text concisely
model: openai/gpt-4o-mini
modelParameters:
temperature: 0.5
messages:
- role: system
content: You are a text summarizer. Your only job is to summarize text given to you.
- role: user
content: |
Summarize the given text, beginning with "Summary -":
<text>
{{input}}
</text>
testData:
- input: |
The quick brown fox jumped over the lazy dog.
The dog was too tired to react.
expected: Summary - A fox jumped over a lazy, unresponsive dog.
evaluators:
- name: Output should start with 'Summary -'
string:
startsWith: 'Summary -'
Loading