Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local Streaming audio is not working in the ios device #1231

Open
srinivas1100 opened this issue Apr 26, 2024 · 4 comments
Open

Local Streaming audio is not working in the ios device #1231

srinivas1100 opened this issue Apr 26, 2024 · 4 comments
Assignees
Labels
1 backlog bug Something isn't working

Comments

@srinivas1100
Copy link

Which API doesn't behave as documented, and how does it misbehave?
I'm using the just_audio package to generate audio from OpenAI and play it. I'm utilizing the http StreamedResponse to generate the audio. After receiving a successful response, I open the HttpServer and bind the response to this server. The code details are provided below. While this setup works fine on Android, it's not functioning properly on iOS.

Minimal reproduction project
Provide a link here using one of two options:

  1. Fork this repository and add the api key https://github.com/srinivas1100/bug-report-audio-package.git
  class OpenAiApi {
  final String _baseUrl = 'https://api.openai.com/v1/audio/speech';
  final String _apiKey;
  AudioPlayer audioPlayer = AudioPlayer();
  OpenAiApi(this._apiKey);
  Future<void> getSpeech(String model, String input, String voice) async {
    log("GET SPEECH IS CALLED");
    final client = http.Client();
    final request = http.Request('POST', Uri.parse(_baseUrl))
      ..headers['Authorization'] = 'Bearer $_apiKey'
      ..headers['Content-Type'] = 'application/json'
      ..body = jsonEncode(<String, String>{
        'model': model,
        'input': input,
        'voice': voice,
      });

    StreamedResponse streamedResponse = await client.send(request);

    // streamedResponse.stream.listen((data) {
    //   log("STREAM DATA : $data");
    // });
    log("STREAM REQUEST IS SENT");

    HttpServer server =
        await HttpServer.bind(InternetAddress.loopbackIPv4, 8080, shared: true);

    try {
      server.listen(
        (HttpRequest serverRequest) async =>
            await streamedResponse.stream.pipe(serverRequest.response),
      );
    } catch (e) {
      log(e.toString());
    }

    log("PORT IS LISTENING ${server.port}");

    // log("STREAM LENGTH : ${streamedResponse.contentLength}");

    await audioPlayer.setUrl('http://localhost:${server.port}');

    // await audioPlayer.load();

    await audioPlayer.play();

    log("AUDIO PLAYER LENGTH : ${audioPlayer.durationStream}");

    log("AUDIO IS PLAYING");
  }
}

To Reproduce (i.e. user steps, not code)
Steps to reproduce the behavior:

  1. Fork the code in this url https://github.com/srinivas1100/bug-report-audio-package.git
  2. launch any ios device
  3. run any real ios device or simulator
  4. click the button it will get the error

Error messages

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: (-11850) Operation Stopped
#0      AudioPlayer._load (package:just_audio/just_audio.dart:869:9)
<asynchronous suspension>
#1      AudioPlayer._setPlatformActive.setPlatform (package:just_audio/just_audio.dart:1465:28)
<asynchronous suspension>

Expected behavior
Once the API returns the streaming response, I bind it to a local server. Then, I use the URL of that local server with the audio player, which automatically plays the audio.

Screenshots
If applicable, No

Desktop (please complete the following information):

  • OS: [MacOS Sonama + Version 14.3]
  • Browser [chrome, safari]

Smartphone (please complete the following information):

  • Device: [iPhone14]
  • OS: [iOS Version 17.4.1]
  • Device: [iPhone15 Plus]
  • OS: [iOS Version 17.4.1]

Flutter SDK version

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.19.5, on macOS 14.3 23D56 darwin-arm64, locale en-IN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.1)
[✓] VS Code (version 1.88.1)
[✓] Connected device (3 available)
[✓] Network resources

• No issues found!

Additional context
This bug is effect my complere application all ios users are unable to play the audio it is critical issue

@srinivas1100 srinivas1100 added 1 backlog bug Something isn't working labels Apr 26, 2024
@Omu0503
Copy link

Omu0503 commented May 23, 2024

Hi! were you able to get over this problem? im facing the same issue

@maeda-takuyaa
Copy link

I have the same problem as you, is there a way to fix this error? Thanks

@willsmanley
Copy link

I'm experiencing the same issue. I also created a minimal reproducible example here: https://github.com/willsmanley/audio-test

This example connects to a websocket server, receives Uint8List bytes, but cant play audio from the stream and eventually results in:
flutter: Error in playing stream: (-11800) The operation could not be completed
flutter: Error in playing stream: MissingPluginException(No implementation found for method load on channel com.ryanheise.just_audio.methods.91d20774-96b0-4621-9a66-8aebce1776d5)

I have the correct ios permissions and flutter clean.

Thank you in advance for any support!

@colarking
Copy link

I have the same error like, my audiobytes. from websocket too, and define a new class extend StreamAudioSource,
but it print Source error Exception;
#1318

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 backlog bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants