Skip to content

Stream audio with POST request #183

@iamklim

Description

@iamklim

Hello! Can I use SwiftAudioPlayer with ElevenLabs Text to Speech Stream API request?

I understand how to stream audio with GET request acc. to docs:

let url = URL(string: "https://randomwebsite.com/audio.mp3")!
SAPlayer.shared.startRemoteAudio(withRemoteUrl: url)
SAPlayer.shared.play()

But what if I need also to attach payload to POST request like

var request = URLRequest(url: url)
request.httpMethod = "POST"
let payload: [String: Any] = [
            "text": "Hello",
            "model_id": "eleven_multilingual_v2",
            "voice_settings": [
              "stability": 0.5,
              "similarity_boost": 0.75,
            ]
        ]
let jsonData = try? JSONSerialization.data(withJSONObject: payload, options: .fragmentsAllowed)
request.httpBody = jsonData

Response returns audio as an audio stream.
Is it possible somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions