Skip to content

Conversation

thenewpotato
Copy link
Contributor

This PR introduces the ability to specify a custom HTTP method (e.g., POST) and an HTTP body when fetching remote audio streams. Previously, all remote audio requests were hardcoded to use the GET method with no body.

Motivation & Context:

The primary motivation for this enhancement is to support services like ElevenLabs, which often require POST requests with a JSON body (e.g., to send text for speech synthesis).

While ElevenLabs is a specific use case driving this change, the implementation focuses on general extensibility. By allowing customization of the HTTP method and body, we make the AudioStreaming module more versatile and capable of integrating with a wider range of audio streaming APIs that may have requirements beyond simple GET requests.

Key Changes:

  • AudioEntryProvider.swift:

    • Extended the AudioEntryProviding protocol and AudioEntryProvider class to accept httpMethod: String? and httpBody: Data? parameters when creating an AudioEntry.
    • Updated internal methods (provideAudioSource, source) to propagate these new parameters.
    • Existing methods for providing audio entries without these parameters default to GET with no body, ensuring backward compatibility.
  • RemoteAudioSource.swift:

    • Added httpMethod and httpBody properties.
    • Modified initializers to accept and store these new parameters.
    • Updated URLRequest creation within startStreamingAudioDataRequest and startGetContentLengthRequest to set the httpMethod and httpBody if provided.
  • AudioPlayer.swift:

    • Added a new public play method:
      public func play(url: URL, httpMethod: String?, httpBody: Data?, headers: [String: String])
      This allows clients to directly leverage the new customization options.

These changes provide a more flexible way to interact with remote audio sources. Existing methods remain in place for backward compatibility.

@dimitris-c
Copy link
Owner

Yeah we could add this in, thanks

@dimitris-c dimitris-c merged commit 4d9bb98 into dimitris-c:main May 30, 2025
1 check passed
@dimitris-c
Copy link
Owner

Made a new release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants