Skip to main content
Share audio content including music, podcasts, voice messages, and sound recordings. Audio posts support comprehensive metadata display with playback controls and rich text descriptions.

Multiple Audio Formats

Support for MP3, WAV, AAC, M4A, OGG, Opus, FLAC and more

Rich Metadata

Automatic duration, bitrate, and quality information

Overview

Audio posts enable sharing of audio content with automatic metadata extraction and playback support:
  • Audio Upload: Upload audio files up to 1GB with 1 hour maximum duration
  • Metadata Extraction: Automatic extraction of duration, bitrate, sample rate, and channels
  • Rich Captions: Text descriptions with mentions and hashtags
  • Parent-Child Structure: Each audio file becomes a child post
  • Playback Controls: Integrated audio player with standard controls
RequirementLimit
File SizeUp to 1GB per file
DurationMaximum 1 hour
File FormatsMP3, WAV, AAC, M4A, OGG, Opus, FLAC
Audio CountMaximum 10 audio files
Audio files must be uploaded first before creating the post. See Audio Handling for upload instructions.

Quick Start

1

Upload Audio

Use the File Repository to upload your audio files and get audio data with metadata
2

Create Post

Use the audio data in your post creation request
3

Handle Response

The post will contain parent and child posts for each audio file

Parameters

ParameterTypeRequiredDescription
textStringCaption text (max 10,000 characters)
audios/audioFilesArrayAudio data or file IDs from upload
targetTypeEnumTarget type (user or community)
targetIdStringTarget ID (userId or communityId)
metadataObjectCustom metadata

Implementation

func createAudioPostExample(audios: [AmityAudioData], text: String) async {
    // Build your post structure
    let builder = AmityAudioPostBuilder()
    builder.setText(text)
    builder.setAudios(audios)
    
    // Create a post from the builder
    do {
        let post = try await postRepository.createAudioPost(
            builder,
            targetId: nil,
            targetType: .user,
            metadata: nil,
            mentionees: nil
        )
    } catch {
        // Handle error here
        print("Failed to create audio post: \(error)")
    }
}

// Complete example with upload and post creation
func uploadAndCreateAudioPost(audioUrl: URL, text: String) async {
    do {
        // Step 1: Upload audio
        let audioData = try await fileRepository.uploadAudio(
            with: audioUrl,
            progress: { progress in
                print("Upload progress: \(progress * 100)%")
            }
        )
        
        // Step 2: Create audio post
        let builder = AmityAudioPostBuilder()
        builder.setText(text)
        builder.setAudios([audioData])
        
        let post = try await postRepository.createAudioPost(
            builder,
            targetId: "community123",
            targetType: .community,
            metadata: nil,
            mentionees: nil
        )
        
        print("Complete! Post ID: \(post.postId)")
    } catch {
        print("Error: \(error)")
    }
}

Best Practices

  • Use appropriate bitrates for content type (128-192 kbps for speech, 256-320 kbps for music)
  • Choose efficient formats like AAC or Opus for better compression
  • Normalize audio levels for consistent playback
  • Consider mono for voice content to reduce file size
// Recommended settings for different content types
const audioSettings = {
  podcast: { format: 'mp3', bitrate: 128, channels: 1 },
  music: { format: 'aac', bitrate: 256, channels: 2 },
  voiceNote: { format: 'opus', bitrate: 64, channels: 1 }
};
  • Display audio duration prominently
  • Show upload progress with percentage
  • Provide audio preview before posting
  • Include meaningful captions and descriptions
  • Handle playback errors gracefully
  • Support background playback where possible
  • Compress audio before upload to reduce file size
  • Implement progress indicators for uploads
  • Cache uploaded audio to avoid re-uploads
  • Use streaming for playback instead of full download
  • Implement retry logic for failed uploads

Troubleshooting

Problem: Audio fails to upload or post creation failsSolutions:
  • Check file size (must be under 1GB)
  • Verify duration (must be under 1 hour)
  • Ensure format is supported (MP3, WAV, AAC, etc.)
  • Check network connection stability
  • Implement retry logic with exponential backoff
Problem: Uploaded audio won’t play or has poor qualitySolutions:
  • Verify format compatibility with target browsers/players
  • Check bitrate isn’t too low (minimum 64 kbps recommended)
  • Ensure sample rate is standard (44.1kHz or 48kHz)
  • Test audio file before upload
  • Use widely supported formats (MP3, AAC)
Problem: Audio duration or other metadata not displayedSolutions:
  • Ensure audio file has valid metadata embedded
  • Use standard formats (MP3, AAC) for better metadata support
  • Re-encode file with proper metadata if needed
  • Verify metadata extraction after upload
Parent-Child Structure: When you upload multiple audio files, the main post becomes the parent, and each audio file creates a child post that users can individually react to and comment on.

Common Use Cases

Podcasts

Share podcast episodes with episode descriptions and show notes

Music Sharing

Share songs, albums, or tracks with artist information

Voice Messages

Quick voice recordings for personal communication

Audio Books

Share narrated content and audiobook chapters

Sound Effects

Share audio samples, beats, and sound effect libraries

Interviews & Discussions

Record and share interview recordings and panel discussions