This commit addresses changes made to update the ElevenLabs API version as per pull request #51 (Update narrator.py to reflect API updates #51 - https://github.com/cbh123/narrator/pull/51). The following changes have been made: narrator.py: - Updated the ElevenLabs client instantiation to the new API format. - Removed the deprecated `set_api_key` and `get_api_key` methods and replaced them with the `ElevenLabs` class instantiation. - Modified the `play_audio` function to handle the audio generator properly by collecting the audio data into a bytes-like object before writing it to a file and playing it. - Added detailed docstrings and comments for better understanding and maintenance of the code. - Ensured that the OpenAI client uses the correct API key and updated the image analysis to handle responses accurately. capture.py: - Ensured the frames folder is created if it doesn't exist. - Updated the webcam initialization check and added a wait time for the camera to adjust light levels. - Adjusted the image resizing logic to improve performance before saving the frame. - Added detailed print statements and comments for clarity and debugging purposes. These changes ensure compatibility with the latest ElevenLabs API and improve the overall robustness and readability of the code. |
||
---|---|---|
assets | ||
frames | ||
.gitignore | ||
README.md | ||
capture.py | ||
narrator.py | ||
requirements.txt |
README.md
David Attenborough narrates your life.
https://twitter.com/charliebholtz/status/1724815159590293764
Want to make your own AI app?
Check out Replicate. We make it easy to run machine learning models with an API.
Setup
Clone this repo, and setup and activate a virtualenv:
python3 -m pip install virtualenv
python3 -m virtualenv venv
source venv/bin/activate
Then, install the dependencies:
pip install -r requirements.txt
Make a Replicate, OpenAI, and ElevenLabs account and set your tokens:
Setting Up Environment Variables
Instead of setting your tokens directly in the terminal, we'll use a .env
file to manage them securely. Follow these steps:
-
Create a file named
.env
in the root directory of your project. -
Add your API keys and voice ID to the
.env
file in the following format:OPENAI_API_KEY=your_openai_api_key ELEVENLABS_API_KEY=your_elevenlabs_api_key ELEVENLABS_VOICE_ID=your_elevenlabs_voice_id
Replace
your_openai_api_key
,your_elevenlabs_api_key
, andyour_elevenlabs_voice_id
with your actual keys and ID. -
The python-dotenv package (already included in
requirements.txt
) will load these variables automatically.
Note: Ensure that .env
is listed in your .gitignore
file to keep your API keys secure.
Make a new voice in Eleven and get the voice id of that voice using their get voices API, or by clicking the flask icon next to the voice in the VoiceLab tab.
export ELEVENLABS_VOICE_ID=<voice-id>
Run it!
In on terminal, run the webcam capture:
python capture.py
In another terminal, run the narrator:
python narrator.py