Merge pull request #26 from gaborcselle/parametrize-voice-id

This commit is contained in:
Charlie Holtz 2023-11-18 11:10:18 -05:00 committed by GitHub
commit 1174275b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -25,14 +25,19 @@ export OPENAI_API_KEY=<token>
export ELEVENLABS_API_KEY=<eleven-token> export ELEVENLABS_API_KEY=<eleven-token>
``` ```
Make a new voice in Eleven and get the voice id of that voice using their [get voices](https://elevenlabs.io/docs/api-reference/voices) API. Make a new voice in Eleven and get the voice id of that voice using their [get voices](https://elevenlabs.io/docs/api-reference/voices) API, or by clicking the flask icon next to the voice in the VoiceLab tab.
```
export ELEVENLABS_VOICE_ID=<voice-id>
```
## Run it! ## Run it!
In on terminal, run the webcam capture:
```bash ```bash
python capture.py python capture.py
``` ```
In one terminal. In the other, run the narrator: In another terminal, run the narrator:
```bash ```bash
python narrator.py python narrator.py

View File

@ -5,10 +5,11 @@ import json
import time import time
import simpleaudio as sa import simpleaudio as sa
import errno import errno
from elevenlabs import generate, play, voices from elevenlabs import generate, play, set_api_key, voices
client = OpenAI() client = OpenAI()
set_api_key(os.environ.get("ELEVENLABS_API_KEY"))
def encode_image(image_path): def encode_image(image_path):
while True: while True:
@ -24,7 +25,7 @@ def encode_image(image_path):
def play_audio(text): def play_audio(text):
audio = generate(text=text, voice="ENfvYmv6CRqDodDZTieQ", model="eleven_turbo_v2") audio = generate(text, voice=os.environ.get("ELEVENLABS_VOICE_ID"))
unique_id = base64.urlsafe_b64encode(os.urandom(30)).decode("utf-8").rstrip("=") unique_id = base64.urlsafe_b64encode(os.urandom(30)).decode("utf-8").rstrip("=")
dir_path = os.path.join("narration", unique_id) dir_path = os.path.join("narration", unique_id)