AI TTS باستخدام Elevenlabs API
ستحتاج أولاً إلى تثبيت المكتبات المطلوبة. يمكنك تثبيتها باستخدام PIP مع الأمر التالي: pip3 install -r requirements.txt
لبيئة معزولة (موصى بها) ، قم بإنشاء وتنشيط بيئة افتراضية باستخدام:
python3 -m venv venv
source venv/bin/activate # On Linux/macOS
venvScriptsactivate # On Windows
pip3 install -r requirements.txt
لاستخدام البرنامج ، تحتاج إلى توفير مفتاح API ElevenLabs الخاص بك. يمكنك الحصول على مفتاح API من خلال التسجيل هنا. بعد الحصول على مفتاح API الخاص بك ، يجب عليك تعيينه كمتغير للبيئة يسمى ElevenLabs_API_Key.
اتبع هذه الخطوات لتعيين متغير البيئة ElevenLabs_API_Key باستمرار (موصى به):
على Linux أو MacOS:
.zshrc الخاص بك مع محرر النص المفضل لديك. على سبيل المثال: nano ~/.zshrcexport ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here بمفتاح API الفعلي.source ~/.zshrc في المحطة لتحميل التغييرات.على Windows:
ELEVENLABS_API_KEY للاسم المتغير ومفتاح API الفعلي للقيمة المتغيرة.بدلاً من ذلك ، يمكنك تعيين متغير البيئة ElevenLabs_API_Key مؤقتًا ، للجلسة الحالية فقط ، على النحو التالي:
على Linux أو MacOS:
export ELEVENLABS_API_KEY=your_api_key_hereyour_api_key_here بمفتاح API الفعلي.على Windows:
setx ELEVENLABS_API_KEY "your_api_key_here"your_api_key_here بمفتاح API الفعلي.بمجرد تعيين متغير البيئة ElevenLabs_API_KEY ، يمكنك تشغيل البرنامج كما هو موضح في قسم الاستخدام أدناه.
TTS.py [-h] (-a | -s | --get-voices) [-v VOICE_ID]
[-t TEXT | -f FILE | -u URL | --ai | --gear | --business | --culture | --science | --security]
[-m MODEL] [-o OUTPUT]
-h, --help show this help message and exit
-a, --audio Use /v1/text-to-speech API endpoint
-s, --stream Use /v1/text-to-speech/{voice_id}/stream API endpoint
--get-voices Retrieve the available voices
-v VOICE_ID, --voice-id VOICE_ID Voice ID to use for the conversion
-t TEXT, --text TEXT Text to convert to speech
-f FILE, --file FILE Text file to convert to speech
-u URL, --url URL BETA: URL of article to convert to speech
--ai Read the latest AI news
--gear Read the latest gear news
--business Read the latest business news
--culture Read the latest culture news
--science Read the latest science news
--security Read the latest security news
-m MODEL, --model MODEL ElevenLabs model to use
-o OUTPUT, --output OUTPUT Output to a .wav file
لتحويل النص في input.txt إلى الكلام باستخدام معرف الصوت pninz6OBPGDQGCFMAJGB ، قم بتشغيل الأمر التالي:
python3 TTS.py -a -f input.txt --voice-id pNInz6obpgDQGcFmaJgB
لإدخال سلسلة مباشرة للتحويل إلى الكلام:
python3 TTS.py -a --text "This is an example block of text"
لجلب آخر أخبار الذكاء الاصطناعى وقراءته باستخدام النص إلى الكلام ، قم بتشغيل أحد الأوامر التالية.
لإنشاء ملف صوتي مع الاسم الافتراضي Audio.wav:
python3 TTS.py -a --AI
لإنشاء ملف صوتي باسم مخصص:
python3 TTS.py -a --AI -o AI_news.wav
لدفق الصوت فقط:
python3 TTS.py -s --AI