Created
March 19, 2024 09:28
-
-
Save springcoil/b876ca9e653b3c6e4d815802b8b4b5b3 to your computer and use it in GitHub Desktop.
Denoising audio in python
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
import os | |
import audiostack | |
FILE_TO_DENOISE = "samples/noisy_sample.mp3" # Try replacing with your own noisy audio file | |
audiostack.api_key = os.environ["AUDIOSTACK_API_KEY"] | |
def main() -> None: | |
# 1. How to upload a noisy audio file | |
print( | |
f"Uploading {FILE_TO_DENOISE} to your content area on platform.audiostack.ai." | |
) | |
file = audiostack.Content.File.create( | |
FILE_TO_DENOISE, | |
uploadPath="how-to-guides/denoise_audio_example.mp3", | |
fileType="audio", | |
) | |
fileId = file.fileId | |
print(f"You can now reference this file using the following fileId: `{fileId}`.") | |
# 2. How to use the denoiser functionality via the Audiostack Python SDK | |
print(f"Denoising your file.") | |
response = audiostack.production.suite.Suite.denoise(fileId=fileId, wait=True) | |
print(response) | |
print( | |
f"Your denoised file has been created at `{response.newFileIds[0]['filePath']}` with fileId: `{response.newFileIds[0]['fileId']}`." | |
) | |
# You can also retrieve your denoiser result in the following way: | |
pipelineId = response.pipelineId | |
response = audiostack.production.suite.Suite.get(pipelineId=pipelineId) | |
print(response) | |
# 3. How to download that file from the API | |
file = audiostack.Content.File.get(fileId=response.newFileIds[0]["fileId"]) | |
file.download(fileName="denoised.wav", path="./") | |
print(f"Your denoised file is available at `./denoised.wav`.") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment