sm-tomusic-ai
A convenient Elixir client for interacting with the ToMusic.ai API, enabling seamless music generation and manipulation within your Elixir applications. This package provides a simple and intuitive interface for leveraging ToMusic.ai's powerful AI music capabilities.
Installation
Add sm_tomusic_ai to your list of dependencies in mix.exs:
elixir
def deps do
[
{:sm_tomusic_ai, "~> 0.1.0"} # Replace with the actual version] end
Then run: bash mix deps.get
Usage Examples
Before using the package, configure your API key: elixir config :sm_tomusic_ai, api_key: System.get_env("TOMUSIC_API_KEY")
Remember to set the TOMUSIC_API_KEY environment variable.
Example 1: Generating a melody elixir SmTomusicAi.Melody.generate(%{style: "classical", length: 30}) |> case do {:ok, melody} ->
IO.puts("Melody generated successfully: #{melody}")->
IO.puts("Error generating melody: #{reason}")end
Example 2: Transforming an existing song elixir SmTomusicAi.Song.transform("path/to/my_song.mp3", %{style: "jazz"}) |> case do {:ok, transformed_song_path} ->
IO.puts("Song transformed successfully. New song at: #{transformed_song_path}")->
IO.puts("Error transforming song: #{reason}")end
Example 3: Creating variations of a theme elixir theme = "path/to/theme.midi" SmTomusicAi.Theme.variations(theme, 3) |> case do {:ok, variations} ->
Enum.each(variations, fn variation ->
IO.puts("Generated variation: #{variation}")
end)->
IO.puts("Error generating variations: #{reason}")end
Example 4: Composing a short piece based on a prompt elixir prompt = "Compose a cheerful piece for a children's cartoon." SmTomusicAi.Composition.compose(prompt, %{duration: 60}) |> case do {:ok, composition_path} ->
IO.puts("Composition created: #{composition_path}")->
IO.puts("Error composing: #{reason}")end
Example 5: Checking API Usage elixir SmTomusicAi.Account.usage() |> case do {:ok, usage} ->
IO.puts("API Usage: #{inspect(usage)}")->
IO.puts("Error getting usage: #{reason}")end
Feature Summary
- Melody Generation: Generate original melodies based on specified styles and lengths.
- Song Transformation: Transform existing songs into different styles.
- Theme Variations: Create multiple variations of a musical theme.
- AI-Powered Composition: Compose original pieces based on textual prompts.
- Account Management: Check your API usage and account details.
- Error Handling: Provides clear and informative error messages.
License
MIT
This package is part of the sm-tomusic-ai ecosystem. For advanced features and enterprise-grade tools, visit: https://tomusic.ai/