# AudioEditor — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/audio_editor

Category: Media

Manages audio metadata editing, allowing users to seed data, modify tags, and optionally generate new audio from text

Public component import: `AudioEditor`

Public manager import: `create_audio_editor_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { AudioEditor, create_audio_editor_manager } from "sveltekit-ui"

  // This editor needs your audio backend. POST /api/audio accepts
  // multipart audio/tags/file_name (or text_to_audio_input/voice_id)
  // and returns { id }. GET /api/files/{id} serves the resulting audio.
  // POST /api/audio/read-tags accepts multipart file and returns
  // { raw: { TIT2: "Title", TPE1: "Artist", ... } } when seeding an audio file.
  let saved_name = $state("")

  const manager = create_audio_editor_manager({
    is_popover: false,
    api_prefix: "/api",
    fetch_path_audio_read_tags: "/api/audio/read-tags",
    fetch_path_audio_post: "/api/audio",
    file_prefix: "/api/files/",
    on_finish: (result) => { saved_name = result.file_name },
  })
</script>

<AudioEditor {manager} />
{#if saved_name}<p role="status">Saved {saved_name}</p>{/if}
```

## Configuration

### `account`

- type: object
- default: null
- description: an account object used for saving new audio to a specific user or namespace

### `storage`

- type: object
- default: null
- description: storage definition for retrieving/saving audio and images

### `locally_uploaded_files`

- type: any
- default: null
- description: reference to any local file state you want to pass in

### `is_disabled`

- type: boolean
- default: false
- description: disables certain inputs and buttons if true

### `api_prefix`

- type: string
- default: /api
- description: base URL for your app-provided audio and storage endpoints; no backend service is included

### `fetch_path_audio_read_tags`

- type: string
- default: /api/tools/audio/read_tags
- description: POST endpoint accepting multipart file data and returning { raw: ID3 tags }; defaults to api_prefix + /tools/audio/read_tags

### `fetch_path_audio_post`

- type: string
- default: /api/tools/audio
- description: POST endpoint accepting multipart audio and metadata fields, returning { id }; defaults to api_prefix + /tools/audio

### `storage_src`

- type: string
- default: /api/storage/{storage_id}
- description: stored-media URL template for all file pickers; defaults to api_prefix + /storage/{storage_id}

### `file_prefix`

- type: string
- default: /api/storage/
- description: prefix for retrieving generated audio by id; defaults to api_prefix + /storage/

### `storage_default_folder_path`

- type: string
- default: null
- description: if using a storage system, sets the default folder path for picking files

### `on_finish`

- type: function
- default: null
- description: callback triggered upon finishing (e.g., passing the newly generated audio file object)

## Methods

### `init()`

- description: initializes the manager state and sub-managers with config values
- parameters:
  - config: object
- returns: void

### `seed()`

- description: loads existing audio data or text-based info into the manager
- parameters:
  - input: object
- returns: void

### `get_audio_metadata()`

- description: reads metadata (id3 tags, cover image) from a given audio file via api call
- parameters:
  - audio_file: file
- returns: promise<object>

### `resize_and_convert_image()`

- description: resizes and converts an image to dataurl with a specified format
- parameters:
  - src: string
  - max_width: number
  - max_height: number
  - output_format: string
- returns: promise<string>

### `set_text_to_audio_input()`

- description: updates the text content used to generate audio via text-to-speech
- parameters:
  - val: string
- returns: void

### `generate_new_audio()`

- description: submits form data to server to either re-tag existing audio or generate a text-to-audio file
- parameters:
- returns: promise<void>

### `download_audio_file()`

- description: locally downloads the generated audio file to the user's machine
- parameters:
- returns: void

### `set_is_text_to_audio()`

- description: toggles whether the editor is using text-to-audio or a standard audio file
- parameters:
  - is_text_to_audio_input: boolean
- returns: void

### `clear()`

- description: resets the form fields and metadata within the manager
- parameters:
- returns: void

### `finish()`

- description: invokes on_finish callback with the final generated audio file object
- parameters:
- returns: void

## Returned state

### `id`

- type: string
- description: unique id for the audio editor instance

### `account`

- type: object
- description: the currently set account if any

### `is_text_to_audio`

- type: boolean
- description: true if text-to-speech is being used instead of a file

### `error_message`

- type: string
- description: captures any error output from generating or tagging audio

### `success_message`

- type: string
- description: captures any success message after generating or tagging audio

### `generate_audio_changes_button_manager`

- type: object
- description: button manager controlling the 'generate audio changes' action

### `use_text_to_audio_button_manager`

- type: object
- description: button manager controlling the switch to text-to-audio

### `select_file_from_storage_button_manager`

- type: object
- description: button manager for opening the storage picker to choose an audio file

### `use_mp3_file_button_manager`

- type: object
- description: button manager controlling the switch to a standard mp3 file instead of text-to-audio

### `text_to_audio_text_input_manager`

- type: object
- description: text input manager for user-provided text that will be converted to audio

### `file_name_text_input_manager`

- type: object
- description: text input manager for specifying the resulting mp3 file name

### `additional_tags_input_prepped`

- type: object
- description: an object keyed by extra id3 tag frames, each containing a text_input_manager

### `additional_tag_keys_ordered`

- type: array
- description: list of additional tag keys in the display order

### `audio_storage_picker_manager`

- type: object
- description: storage picker manager for the main audio file

### `title_text_input_manager`

- type: object
- description: text input manager for the 'title' id3 tag (TIT2)

### `album_title_text_input_manager`

- type: object
- description: text input manager for the 'album' id3 tag (TALB)

### `image_storage_picker_manager`

- type: object
- description: storage picker for the embedded album/cover image

### `image_description_text_input_manager`

- type: object
- description: text input manager for the embedded image's description field

### `artist_text_input_manager`

- type: object
- description: text input manager for the 'artist' id3 tag (TPE1)

### `lyrics_text_input_manager`

- type: object
- description: text area manager for the USLT lyrics tag

### `release_year_text_input_manager`

- type: object
- description: numeric input manager for the 'release year' tag (TYER)

### `language_dropdown_manager`

- type: object
- description: dropdown manager for the TLAN language tag

### `is_popover`

- type: boolean
- description: determines whether the audio editor is displayed within a popover

### `popover_manager`

- type: object
- description: controls the main popover for editing audio

### `text_to_audio_time_in_minutes`

- type: number
- description: estimates how long the text might take to generate as audio

### `voice_options`

- type: array
- description: list of predefined voice profiles available for text-to-audio

### `voice_id`

- type: string
- description: selected voice identifier for text-to-audio generation

### `edit_voice_popover_manager`

- type: object
- description: popover manager for selecting a voice from a list

### `edit_voice_button_manager`

- type: object
- description: button manager for triggering the voice selection popover

### `seed_from_input_popover_manager`

- type: object
- description: popover manager for seeding audio data from another file

### `seed_from_input_popover_button_manager`

- type: object
- description: button manager for opening the seed-from-input popover

### `seed_audio_storage_picker_manager`

- type: object
- description: storage picker used within the seed-from-input popover

### `is_loading_generate_audio`

- type: boolean
- description: indicates if the component is currently generating new audio or applying tags

### `generated_audio_file_obj`

- type: object
- description: represents the newly generated audio file, including file, src, and metadata

### `audio_manager`

- type: object
- description: an instance of create_audio_manager that can play the generated audio

### `clear_generated_audio_button_manager`

- type: object
- description: button manager to clear any existing generated audio

### `download_audio_file_button_manager`

- type: object
- description: button manager to download the newly generated audio file

### `clear_button_manager`

- type: object
- description: button manager to reset/clear the entire audio editor

### `finish_button_manager`

- type: object
- description: button manager to finalize/close the editor and invoke on_finish callback

### `additional_metatags_dropdown_manager`

- type: object
- description: dropdown manager for selecting additional id3 frames to expose
