-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added create a dub example * partial improvement, still blocked on the sdk * add watermark by default
- Loading branch information
Showing
10 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: Ruff | ||
on: [push, pull_request] | ||
jobs: | ||
ruff: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: chartboost/ruff-action@v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ Thumbs.db | |
# env | ||
.env* | ||
!.env.example | ||
|
||
# formatters | ||
.ruff_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
repos: | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
# Ruff version. | ||
rev: v0.3.7 | ||
hooks: | ||
# Run the linter. | ||
- id: ruff | ||
args: ["--fix", "--select", "I"] | ||
# Run the formatter. | ||
- id: ruff-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Python: Current File", | ||
"type": "python", | ||
"request": "launch", | ||
"program": "${file}", | ||
"console": "integratedTerminal", | ||
"justMyCode": true | ||
} | ||
] | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ELEVENLABS_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
dubbed_file.mp4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import os | ||
import time | ||
|
||
import requests | ||
from dotenv import load_dotenv | ||
from elevenlabs.client import ElevenLabs | ||
|
||
load_dotenv() | ||
|
||
ELEVENLABS_API_KEY = os.getenv("ELEVENLABS_API_KEY") | ||
|
||
if ELEVENLABS_API_KEY is None: | ||
raise ValueError( | ||
"ELEVENLABS_API_KEY environment variable not found, please copy the .env.example file to .env and fill in the API key" | ||
) | ||
|
||
client = ElevenLabs(api_key=ELEVENLABS_API_KEY) | ||
|
||
|
||
def create_dub( | ||
file_name, format, input_file_path, output_file_path, source_lang, target_language | ||
): | ||
with open(input_file_path, "rb") as audio_file: | ||
response = client.dubbing.dub_a_video_or_an_audio_file( | ||
file=(file_name, audio_file, format), | ||
target_lang=target_language, | ||
mode="automatic", | ||
source_lang="en", | ||
num_speakers=1, | ||
watermark=True, # reduces the characters used | ||
) | ||
|
||
dubbing_id = response.dubbing_id | ||
|
||
for i in range(1000): | ||
headers = { | ||
"xi-api-key": ELEVENLABS_API_KEY, | ||
} | ||
|
||
metadata = client.dubbing.get_dubbing_project_metadata(dubbing_id=dubbing_id) | ||
if metadata.status == "dubbed": | ||
# TODO: fix the response type of client.dubbing.get_dubbed_file | ||
response = requests.get( | ||
"https://api.elevenlabs.io/v1/dubbing/" | ||
+ dubbing_id | ||
+ "/audio/" | ||
+ target_language, | ||
headers=headers, | ||
) | ||
|
||
if response.status_code == 200: | ||
with open(output_file_path, "wb") as file: | ||
file.write(response.content) | ||
print("Dubbing complete and saved to dubbed_file.mp4") | ||
|
||
return | ||
|
||
elif metadata.status == "dubbing": | ||
print("Dubbing in progress... Will check status again in 10 seconds") | ||
time.sleep(10) | ||
else: | ||
print("Dubbing failed", response.json()) | ||
return | ||
|
||
if i == 10: | ||
print("Dubbing timed out") | ||
|
||
|
||
if __name__ == "__main__": | ||
input_file_path = os.path.join(os.path.dirname(__file__), "../example_speech.mp3") | ||
output_file_path = "dubbed_file.mp4" | ||
|
||
source_language = "en" | ||
target_language = "es" | ||
create_dub( | ||
"example_speech.mp3", | ||
"audio/mpeg", | ||
input_file_path, | ||
output_file_path, | ||
source_language, | ||
target_language, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
elevenlabs==1.1.2 | ||
python-dotenv==1.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pre-commit==3.7.0 | ||
ruff==0.3.7 |