diff --git a/nbs/Stable_Audio_API.ipynb b/nbs/Stable_Audio_API.ipynb index 18fc971..9808e0a 100644 --- a/nbs/Stable_Audio_API.ipynb +++ b/nbs/Stable_Audio_API.ipynb @@ -1,491 +1,838 @@ { - "cells": [ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "cellView": "form", + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "F5_PrjeRDnNl", + "outputId": "37d66747-99cb-4ebf-c863-1e6f9a5e98c8" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter your API Key··········\n" + ] + } + ], + "source": [ + "#@title Enter your Stability API key\n", + "# @markdown To get your API key visit https://platform.stability.ai/account/keys\n", + "import getpass, requests, IPython\n", + "STABILITY_KEY = getpass.getpass('Enter your API Key')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "zTSNd1x2PF-0", + "outputId": "65c20bd5-a1c4-4cba-bdd5-f443b937ea0e" + }, + "outputs": [ { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "cellView": "form", - "id": "F5_PrjeRDnNl" - }, - "outputs": [], - "source": [ - "#@title Enter your Stability API key\n", - "# @markdown To get your API key visit https://platform.stability.ai/account/keys\n", - "import getpass, requests, IPython\n", - "STABILITY_KEY = getpass.getpass('Enter your API Key')" + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved txt2audio.mp3\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Stable Audio 2: Text to Audio\n", + "\n", + "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", + "duration = 190 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 50 #@param {type:\"number\"}\n", + "cfg_scale = 7.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2/text-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"image\": None},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " \"model\": \"stable-audio-2\"\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"txt2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "qLeELUeIPF-0", + "outputId": "3571850d-f5be-4e6a-d204-8e8d44fb9912" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved txt2audio.mp3\n" + ] }, { - "cell_type": "code", - "execution_count": 2, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Saved txt2audio.mp3\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } + "data": { + "text/html": [ + "\n", + " \n", + " " ], - "source": [ - "#@title Stable Audio 2: Text to Audio\n", - "\n", - "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", - "duration = 190 #@param {type:\"number\"}\n", - "seed = 0 #@param {type:\"number\"}\n", - "steps = 50 #@param {type:\"number\"}\n", - "cfg_scale = 7.0 #@param {type:\"number\"}\n", - "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", - "response = requests.post(\n", - " \"https://api.stability.ai/v2beta/audio/stable-audio-2/text-to-audio\",\n", - " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", - " files={\"image\": None},\n", - " data={\n", - " \"prompt\" : prompt,\n", - " \"duration\": duration,\n", - " \"seed\": seed,\n", - " \"steps\": steps,\n", - " \"cfg_scale\" : cfg_scale,\n", - " \"output_format\": output_format,\n", - " \"model\": \"stable-audio-2\"\n", - " }\n", - ")\n", - "if not response.ok:\n", - " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", - "\n", - "# Save and show the result\n", - "filename = f\"txt2audio.mp3\"\n", - "with open(filename, \"wb\") as f:\n", - " f.write(response.content)\n", - "print(f\"Saved {filename}\")\n", - "\n", - "IPython.display.display(IPython.display.Audio(filename))" + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Stable Audio 2.5: Text to Audio\n", + "\n", + "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", + "duration = 190 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "cfg_scale = 1.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2/text-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"image\": None},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " \"model\": \"stable-audio-2.5\"\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"txt2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "KuXaEUWsPF-0", + "outputId": "cf1a2553-71c7-409a-dc64-514f32a3a579" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved audio2audio.mp3\n", + "\n", + "Original audio:\n" + ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Saved txt2audio.mp3\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } + "data": { + "text/html": [ + "\n", + " \n", + " " ], - "source": [ - "#@title Stable Audio 2.5: Text to Audio\n", - "\n", - "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", - "duration = 190 #@param {type:\"number\"}\n", - "seed = 0 #@param {type:\"number\"}\n", - "steps = 8 #@param {type:\"number\"}\n", - "cfg_scale = 1.0 #@param {type:\"number\"}\n", - "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", - "response = requests.post(\n", - " \"https://api.stability.ai/v2beta/audio/stable-audio-2/text-to-audio\",\n", - " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", - " files={\"image\": None},\n", - " data={\n", - " \"prompt\" : prompt,\n", - " \"duration\": duration,\n", - " \"seed\": seed,\n", - " \"steps\": steps,\n", - " \"cfg_scale\" : cfg_scale,\n", - " \"output_format\": output_format,\n", - " \"model\": \"stable-audio-2.5\"\n", - " }\n", - ")\n", - "if not response.ok:\n", - " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", - "\n", - "# Save and show the result\n", - "filename = f\"txt2audio.mp3\"\n", - "with open(filename, \"wb\") as f:\n", - " f.write(response.content)\n", - "print(f\"Saved {filename}\")\n", - "\n", - "IPython.display.display(IPython.display.Audio(filename))" + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Saved audio2audio.mp3\n", - "\n", - "Original audio:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Generation result:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } + "data": { + "text/html": [ + "\n", + " \n", + " " ], - "source": [ - "#@title Stable Audio 2: Audio to Audio\n", - "\n", - "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", - "#@markdown - Right click on it and choose Copy path\n", - "#@markdown - Paste that path into audio field below\n", - "#@markdown

\n", - "\n", - "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", - "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", - "duration = 45 #@param {type:\"number\"}\n", - "seed = 0 #@param {type:\"number\"}\n", - "steps = 50 #@param {type:\"number\"}\n", - "cfg_scale = 7.0 #@param {type:\"number\"}\n", - "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", - "strength = 0.5 #@param {type:\"number\"}\n", - "\n", - "response = requests.post(\n", - " \"https://api.stability.ai/v2beta/audio/stable-audio-2/audio-to-audio\",\n", - " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", - " files={\"audio\": open(audio, \"rb\")},\n", - " data={\n", - " \"prompt\" : prompt,\n", - " \"duration\": duration,\n", - " \"seed\": seed,\n", - " \"steps\": steps,\n", - " \"cfg_scale\" : cfg_scale,\n", - " \"output_format\": output_format,\n", - " \"strength\": strength,\n", - " \"model\": \"stable-audio-2\"\n", - " }\n", - ")\n", - "if not response.ok:\n", - " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", - "\n", - "# Save and show the result\n", - "filename = f\"audio2audio.mp3\"\n", - "with open(filename, \"wb\") as f:\n", - " f.write(response.content)\n", - "print(f\"Saved {filename}\")\n", - "\n", - "print(\"\\nOriginal audio:\")\n", - "IPython.display.display(IPython.display.Audio(audio))\n", - "\n", - "print(\"\\nGeneration result:\")\n", - "IPython.display.display(IPython.display.Audio(filename))" + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Stable Audio 2: Audio to Audio\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown

\n", + "\n", + "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", + "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 50 #@param {type:\"number\"}\n", + "cfg_scale = 7.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "strength = 0.5 #@param {type:\"number\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2/audio-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " \"strength\": strength,\n", + " \"model\": \"stable-audio-2\"\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"audio2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "Ph6QrOzrPF-1", + "outputId": "15d6eb71-57b5-4d8b-80a8-c2f3d6c2fef8" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved audio2audio.mp3\n", + "\n", + "Original audio:\n" + ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Saved audio2audio.mp3\n", - "\n", - "Original audio:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Generation result:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } + "data": { + "text/html": [ + "\n", + " \n", + " " ], - "source": [ - "#@title Stable Audio 2.5: Audio to Audio\n", - "\n", - "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", - "#@markdown - Right click on it and choose Copy path\n", - "#@markdown - Paste that path into audio field below\n", - "#@markdown

\n", - "\n", - "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", - "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", - "duration = 45 #@param {type:\"number\"}\n", - "seed = 0 #@param {type:\"number\"}\n", - "steps = 8 #@param {type:\"number\"}\n", - "cfg_scale = 1.0 #@param {type:\"number\"}\n", - "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", - "strength = 0.5 #@param {type:\"number\"}\n", - "\n", - "response = requests.post(\n", - " \"https://api.stability.ai/v2beta/audio/stable-audio-2/audio-to-audio\",\n", - " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", - " files={\"audio\": open(audio, \"rb\")},\n", - " data={\n", - " \"prompt\" : prompt,\n", - " \"duration\": duration,\n", - " \"seed\": seed,\n", - " \"steps\": steps,\n", - " \"cfg_scale\" : cfg_scale,\n", - " \"output_format\": output_format,\n", - " \"strength\": strength,\n", - " \"model\": \"stable-audio-2.5\"\n", - " }\n", - ")\n", - "if not response.ok:\n", - " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", - "\n", - "# Save and show the result\n", - "filename = f\"audio2audio.mp3\"\n", - "with open(filename, \"wb\") as f:\n", - " f.write(response.content)\n", - "print(f\"Saved {filename}\")\n", - "\n", - "print(\"\\nOriginal audio:\")\n", - "IPython.display.display(IPython.display.Audio(audio))\n", - "\n", - "print(\"\\nGeneration result:\")\n", - "IPython.display.display(IPython.display.Audio(filename))" + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] }, { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "TDWW5DQbDnNo" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Saved inpaint.mp3\n", - "\n", - "Original audio:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\n", - "Generation result:\n" - ] - }, - { - "data": { - "text/html": [ - "\n", - " \n", - " " - ], - "text/plain": [ - "" - ] - }, - "metadata": {}, - "output_type": "display_data" - } + "data": { + "text/html": [ + "\n", + " \n", + " " ], - "source": [ - "#@title Inpaint\n", - "\n", - "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", - "#@markdown - Right click on it and choose Copy path\n", - "#@markdown - Paste that path into audio field below\n", - "#@markdown

\n", - "\n", - "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", - "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", - "duration = 45 #@param {type:\"number\"}\n", - "seed = 0 #@param {type:\"number\"}\n", - "steps = 8 #@param {type:\"number\"}\n", - "cfg_scale = 1.0 #@param {type:\"number\"}\n", - "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", - "mask_start = 15.0 #@param {type:\"number\"}\n", - "mask_end = 40.0 #@param {type:\"number\"}\n", - "\n", - "response = requests.post(\n", - " \"https://api.stability.ai/v2beta/audio/stable-audio-2/inpaint\",\n", - " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", - " files={\"audio\": open(audio, \"rb\")},\n", - " data={\n", - " \"prompt\" : prompt,\n", - " \"duration\": duration,\n", - " \"seed\": seed,\n", - " \"steps\": steps,\n", - " \"cfg_scale\" : cfg_scale,\n", - " \"output_format\": output_format,\n", - " \"mask_start\": mask_start,\n", - " \"mask_end\": mask_end\n", - " }\n", - ")\n", - "if not response.ok:\n", - " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", - "\n", - "# Save and show the result\n", - "filename = f\"inpaint.mp3\"\n", - "with open(filename, \"wb\") as f:\n", - " f.write(response.content)\n", - "print(f\"Saved {filename}\")\n", - "\n", - "print(\"\\nOriginal audio:\")\n", - "IPython.display.display(IPython.display.Audio(audio))\n", - "\n", - "print(\"\\nGeneration result:\")\n", - "IPython.display.display(IPython.display.Audio(filename))" + "text/plain": [ + "" ] + }, + "metadata": {}, + "output_type": "display_data" } - ], - "metadata": { + ], + "source": [ + "#@title Stable Audio 2.5: Audio to Audio\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown

\n", + "\n", + "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", + "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "cfg_scale = 1.0 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "strength = 0.5 #@param {type:\"number\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2/audio-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"cfg_scale\" : cfg_scale,\n", + " \"output_format\": output_format,\n", + " \"strength\": strength,\n", + " \"model\": \"stable-audio-2.5\"\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"audio2audio.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "TDWW5DQbDnNo", + "outputId": "b5c80e6e-4ede-41b6-a8e0-49ede9bd915d" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Saved inpaint.mp3\n", + "\n", + "Original audio:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Stable Audio 2.5: Inpaint\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown

\n", + "\n", + "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", + "audio = \"/content/piano.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "mask_start = 15.0 #@param {type:\"number\"}\n", + "mask_end = 40.0 #@param {type:\"number\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio-2/inpaint\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\" : prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"output_format\": output_format,\n", + " \"mask_start\": mask_start,\n", + " \"mask_end\": mask_end\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "\n", + "# Save and show the result\n", + "filename = f\"inpaint.mp3\"\n", + "with open(filename, \"wb\") as f:\n", + " f.write(response.content)\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 127 + }, + "id": "H9LvE4xDPF-1", + "outputId": "fdf72165-f04a-4a0f-ebae-858397252a69" + }, + "outputs": [], + "source": [ + "#@title Stable Audio 3: Text to Audio\n", + "import time\n", + "\n", + "prompt = \"Genre: UK Bass | Instruments: 707 Drum Machine, Strings, 808 bass stabs, Beautiful Synths\" #@param {type:\"string\"}\n", + "duration = 190 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio/text-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"application/json\"},\n", + " files={\"image\": None},\n", + " data={\n", + " \"prompt\": prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"output_format\": output_format,\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "generation_id = response.json()[\"id\"]\n", + "print(f\"Generation queued: {generation_id}\")\n", + "\n", + "filename = \"txt2audio.mp3\"\n", + "while True:\n", + " poll = requests.get(\n", + " f\"https://api.stability.ai/v2beta/audio/results/{generation_id}\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " )\n", + " if poll.status_code == 200:\n", + " with open(filename, \"wb\") as f:\n", + " f.write(poll.content)\n", + " break\n", + " elif poll.status_code == 202:\n", + " print(\"Still processing, waiting 10s...\")\n", + " time.sleep(10)\n", + " else:\n", + " raise Exception(f\"HTTP {poll.status_code}: {poll.text}\")\n", + "\n", + "print(f\"Saved {filename}\")\n", + "IPython.display.display(IPython.display.Audio(filename))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 255 + }, + "id": "LT5kti2-PF-1", + "outputId": "0d0a2908-f365-4055-f2f3-1a9cd120282d" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generation queued: 22c8b3deebae0fc7c40ee571853e11e2d3960ac58364262a20f4108d6ffd70fa\n", + "Still processing, waiting 10s...\n", + "Saved audio2audio.mp3\n", + "\n", + "Original audio:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#@title Stable Audio 3: Audio to Audio\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown - Or use txt2audio.mp3 generated in cell above\n", + "\n", + "#@markdown

\n", + "import time\n", + "\n", + "prompt = \"Lofi hip hop beat, chillhop\" #@param {type:\"string\"}\n", + "audio = \"txt2audio.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio/audio-to-audio\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"application/json\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\": prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"output_format\": output_format,\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "generation_id = response.json()[\"id\"]\n", + "print(f\"Generation queued: {generation_id}\")\n", + "\n", + "filename = \"audio2audio.mp3\"\n", + "while True:\n", + " poll = requests.get(\n", + " f\"https://api.stability.ai/v2beta/audio/results/{generation_id}\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " )\n", + " if poll.status_code == 200:\n", + " with open(filename, \"wb\") as f:\n", + " f.write(poll.content)\n", + " break\n", + " elif poll.status_code == 202:\n", + " print(\"Still processing, waiting 10s...\")\n", + " time.sleep(10)\n", + " else:\n", + " raise Exception(f\"HTTP {poll.status_code}: {poll.text}\")\n", + "\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { "colab": { - "provenance": [] + "base_uri": "https://localhost:8080/", + "height": 255 + }, + "id": "YDMmLouvPF-1", + "outputId": "366b5f28-02bd-4409-a3c4-0d91cb3605d2" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Generation queued: 45db29dd842204a20ca57c588aa0df3d1cde86df995fae748bdd7501c9f3043c\n", + "Still processing, waiting 10s...\n", + "Saved inpaint.mp3\n", + "\n", + "Original audio:\n" + ] + }, + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" }, - "kernelspec": { - "display_name": ".venv", - "language": "python", - "name": "python3" + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Generation result:\n" + ] }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.13.3" + { + "data": { + "text/html": [ + "\n", + " \n", + " " + ], + "text/plain": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" } + ], + "source": [ + "#@title Stable Audio 3: Inpaint\n", + "\n", + "#@markdown - Drag and drop a .wav or .mp3 to file folder on left\n", + "#@markdown - Right click on it and choose Copy path\n", + "#@markdown - Paste that path into audio field below\n", + "#@markdown - Or use txt2audio.mp3 generated in cell above\n", + "#@markdown

\n", + "import time\n", + "\n", + "prompt = \"Piano solo\" #@param {type:\"string\"}\n", + "audio = \"txt2audio.mp3\" #@param {type:\"string\"}\n", + "duration = 45 #@param {type:\"number\"}\n", + "seed = 0 #@param {type:\"number\"}\n", + "steps = 8 #@param {type:\"number\"}\n", + "output_format = \"mp3\" #@param ['mp3', 'wav'] {type:\"string\"}\n", + "mask_start = 30 #@param {type:\"number\"}\n", + "mask_end = 45 #@param {type:\"number\"}\n", + "\n", + "response = requests.post(\n", + " \"https://api.stability.ai/v2beta/audio/stable-audio/inpaint\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"application/json\"},\n", + " files={\"audio\": open(audio, \"rb\")},\n", + " data={\n", + " \"prompt\": prompt,\n", + " \"duration\": duration,\n", + " \"seed\": seed,\n", + " \"steps\": steps,\n", + " \"output_format\": output_format,\n", + " \"mask_start\": mask_start,\n", + " \"mask_end\": mask_end,\n", + " }\n", + ")\n", + "if not response.ok:\n", + " raise Exception(f\"HTTP {response.status_code}: {response.text}\")\n", + "generation_id = response.json()[\"id\"]\n", + "print(f\"Generation queued: {generation_id}\")\n", + "\n", + "filename = \"inpaint.mp3\"\n", + "while True:\n", + " poll = requests.get(\n", + " f\"https://api.stability.ai/v2beta/audio/results/{generation_id}\",\n", + " headers={\"Authorization\": f\"Bearer {STABILITY_KEY}\", \"Accept\": \"audio/*\"},\n", + " )\n", + " if poll.status_code == 200:\n", + " with open(filename, \"wb\") as f:\n", + " f.write(poll.content)\n", + " break\n", + " elif poll.status_code == 202:\n", + " print(\"Still processing, waiting 10s...\")\n", + " time.sleep(10)\n", + " else:\n", + " raise Exception(f\"HTTP {poll.status_code}: {poll.text}\")\n", + "\n", + "print(f\"Saved {filename}\")\n", + "\n", + "print(\"\\nOriginal audio:\")\n", + "IPython.display.display(IPython.display.Audio(audio))\n", + "\n", + "print(\"\\nGeneration result:\")\n", + "IPython.display.display(IPython.display.Audio(filename))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "OmyFj7nRRuXH" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" }, - "nbformat": 4, - "nbformat_minor": 0 + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.14.4" + } + }, + "nbformat": 4, + "nbformat_minor": 0 }