-
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.
- Loading branch information
Showing
5 changed files
with
80 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 @@ | ||
ELEVENLABS_API_KEY= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,31 @@ | ||
import os | ||
from elevenlabs import SoundGenerationSettingsResponseModel | ||
from elevenlabs.client import ElevenLabs | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
elevenlabs = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY")) | ||
|
||
|
||
def generate_sound_effect(text: str, output_path: str): | ||
print("Generating sound effects...") | ||
|
||
result = elevenlabs.text_to_sound_effect.convert( | ||
text=text, | ||
generation_settings=SoundGenerationSettingsResponseModel( | ||
duration_seconds=10, # Optional | ||
prompt_influence=0.3, # Optional | ||
), | ||
) | ||
|
||
with open(output_path, "wb") as f: | ||
for chunk in result: | ||
f.write(chunk) | ||
|
||
print(f"Audio saved to {output_path}") | ||
|
||
|
||
if __name__ == "__main__": | ||
generate_sound_effect("Dog barking", "output.mp3") |
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 |
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,17 @@ | ||
import os | ||
from main import generate_sound_effect | ||
|
||
|
||
def test_generate_sound_effect(): | ||
FILE_PATH = "output.mp3" | ||
|
||
os.remove(FILE_PATH) if os.path.exists(FILE_PATH) else None | ||
assert not os.path.exists(FILE_PATH) | ||
|
||
generate_sound_effect("Dog barking", FILE_PATH) | ||
|
||
assert os.path.exists(FILE_PATH) | ||
assert os.path.getsize(FILE_PATH) > 0 | ||
|
||
# cleanup | ||
os.remove(FILE_PATH) |