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

no legacy output audio_channel_mask_t found for AudioChannelLayout{ #26

Open
letisoft opened this issue Dec 12, 2024 · 2 comments
Open

Comments

@letisoft
Copy link

Hello,

Your plugin is very promissing!

I tried the plugin with my openAI speech client and no luck:

  int sampleRate = 24000;
  FlutterPcmSound.setLogLevel(LogLevel.verbose);
  FlutterPcmSound.setup(sampleRate: sampleRate, channelCount: 1);

  if (Platform.isAndroid) {
    FlutterPcmSound.setFeedThreshold(-1);
  }
  else {
    FlutterPcmSound.setFeedThreshold(sampleRate ~/ 30);
  }

  Stream<List<int>> resp = await EncodeDecode.getSpeechStream("key",
      "United States, country in North America, a federal republic of 50 states. Besides the 48 conterminous states that occupy the middle latitudes of the continent, the United States includes the state of Alaska, at the northwestern extreme of North America, and the island state of Hawaii, in the mid-Pacific Ocean. The conterminous states are bounded on the north by Canada, on the east by the Atlantic Ocean, on the south by the Gulf of Mexico and Mexico, and on the west by the Pacific Ocean. The United States is the fourth largest country in the world in area (after Russia, Canada, and China). The national capital is Washington, which is coextensive with the District of Columbia, the federal capital region created in 1790."
  );

  StreamSubscription<List<int>> subscription = resp.listen(
      (List<int> chunk) async{
        await FlutterPcmSound.feed(PcmArrayInt16.fromList(chunk));
      },
    onDone: (){
      debugPrint("done");
    },
    onError: (Error err,StackTrace){
      debugPrint("error");
    }
  );

  FlutterPcmSound.start();

then I tried your sample code - still no luck, but at least I can see following error in adb log:

no legacy output audio_channel_mask_t found for AudioChannelLayout{

Any idea?

I have checked the android code (as I have the same working in my native app) but cannot notice anything wrong.

Best regards:
V

@chipweinberger
Copy link
Owner

never seen this error before

@chipweinberger
Copy link
Owner

chipweinberger commented Dec 13, 2024

from chatgpt. try these suggestions. open a PR if you fix it.

ChatGPT

The error message "no legacy output audio_channel_mask_t found for AudioChannelLayout" in the Android Developer Console typically indicates a mismatch or misconfiguration with the audio channel layout settings in your app, especially when working with audio frameworks or libraries. Here are steps to address and fix this issue:


1. Check Audio Channel Configuration

Ensure that the audio channel layout you're specifying is compatible with the Android system's legacy audio masks. Android uses AudioChannelLayout to describe the arrangement of audio channels, and it needs to map to a legacy output audio_channel_mask_t.

  • Common legacy channel masks include:
    • AudioFormat.CHANNEL_OUT_MONO (Mono)
    • AudioFormat.CHANNEL_OUT_STEREO (Stereo)

If you're using a non-standard or custom channel layout, it may not map to these predefined masks.


2. Update Audio Framework Code

If you're using an audio framework, look at the code where AudioTrack or AudioManager is being configured. Specifically, check how the AudioChannelLayout is being defined.

  • For example, if you're using AudioTrack:
AudioTrack audioTrack = new AudioTrack(
    AudioManager.STREAM_MUSIC,
    sampleRate, // e.g., 44100
    AudioFormat.CHANNEL_OUT_STEREO, // Ensure this matches a legacy mask
    AudioFormat.ENCODING_PCM_16BIT,
    bufferSize,
    AudioTrack.MODE_STREAM
);

If AudioFormat.CHANNEL_OUT_STEREO is not compatible, try switching to AudioFormat.CHANNEL_OUT_MONO for testing purposes.


3. Verify Audio Encoding

Ensure the audio encoding format matches the channel layout and is supported by the system. Common formats include:

  • AudioFormat.ENCODING_PCM_16BIT
  • AudioFormat.ENCODING_PCM_FLOAT

Using an unsupported encoding can also trigger issues with channel masks.


4. Check Library/SDK Compatibility

If you are using third-party libraries for audio processing or playback (e.g., ExoPlayer, OpenSL ES, etc.), ensure they are compatible with your Android version.

  • Update the library to the latest version, as newer versions often fix such compatibility issues.
  • Review the library documentation for settings related to channel masks or layouts.

5. Device-Specific Behavior

Some Android devices may handle audio channel configurations differently. Test your app on multiple devices and Android versions to confirm whether the issue is device-specific.

  • For device-specific issues, consider implementing a fallback mechanism. For example, detect the device and adjust the channel layout dynamically.

6. Enable Debugging Logs

Enable detailed logging for your app's audio framework to understand where the configuration mismatch is happening. For example:

Log.d("AudioConfig", "AudioTrack Configuration: Sample Rate=" + sampleRate +
    ", Channel Config=" + channelConfig + ", Encoding=" + audioFormat);

7. Fallback to Legacy Configuration

If you need to support older devices, consider using legacy APIs explicitly. For example, on older Android versions, you might need to explicitly set the audio channel mask:

audioTrack.setPlaybackParameters(new PlaybackParams().setAudioChannelLayout(legacyMask));

8. Review Android Documentation

Refer to the [AudioTrack API documentation](https://developer.android.com/reference/android/media/AudioTrack) and [AudioFormat](https://developer.android.com/reference/android/media/AudioFormat) for guidelines on supported configurations.


If you still face issues, share more details about your app's audio configuration (e.g., how you're creating or playing audio, the specific code snippets, and Android versions affected). This will help narrow down the root cause further.

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

No branches or pull requests

2 participants