tanhakabir / SwiftAudioPlayer

Streaming and realtime audio manipulation with AVAudioEngine
https://medium.com/chameleon-podcast/creating-an-advanced-streaming-audio-engine-for-ios-9fbc7aef4115
MIT License
544 stars 107 forks source link

Stream audio with POST request #183

Open iamklim opened 6 months ago

iamklim commented 6 months ago

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?

mgerstenblatt commented 2 months ago

@iamklim did you find a way to get streaming audio from elevenlabs to work in Swift? I'm trying to do the seame thing.

snboyle16 commented 2 months ago

@iamklim @mgerstenblatt I am trying to figure out the same thing! Any tips?