Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt6 AudioSource on Android: unable to select non-default source
Forum Updated to NodeBB v4.3 + New Features

Qt6 AudioSource on Android: unable to select non-default source

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
3 Posts 2 Posters 386 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    alaurenzi
    wrote on last edited by
    #1

    Dear developers,
    I need to acquire realtime audio from an headset on an Android tablet. After checking the documentation, QAudioSource looks the right tool for the job, and indeed to works perfectly for my application, allowing me to read the acquired audio from the provided QIODevice to then apply custom post-processing. There is though an issue, i.e. I am only able to acquire audio from the default source, that is the internal tablet mic.

    This is also the case when just deploying to the tablet the provided AudioSource Qt Example. I can change the source to said headset from the dropdown menu, yet the sound level (as show by the red progress bar) is always related to the internal mic. (I verify this by gently tapping on the physical mic with a finger, headset being quite far away, and I see audio level saturation).

    I have tried to look at the source code, and actually I am confused as to where the device selection is actually forwarded to the low level OpenSLES code.

    This is what I could understand from the source code:
    a) The user queries for all available input devices via QMediaDevices::audioInputs(), which returns QAudioDevice objects. On Android, this information comes from the native AudioManager (see here and here). Devices are differentiated by their ID, and on my tablet internal mic is 19, headset is 3968.
    b) The user creates a QAudioSource instance passing the QAudioDevice that corresponds to the desired audio input. On Android, this causes the creation of a QAndroidAudioSource (see here) with the underlying device ID (say 3968 in my case)
    c) Here I am a bit lost, as the constructor of QAndroidAudioSource seems not to use the device ID information.. or, more precisely, it only compares it against a few "presets" (see here).

    Could you help me understand how this works in the low level, and how to achieve my goal of recording from a non-default source?

    Thanks,
    Arturo

    P 1 Reply Last reply
    0
    • A alaurenzi

      Dear developers,
      I need to acquire realtime audio from an headset on an Android tablet. After checking the documentation, QAudioSource looks the right tool for the job, and indeed to works perfectly for my application, allowing me to read the acquired audio from the provided QIODevice to then apply custom post-processing. There is though an issue, i.e. I am only able to acquire audio from the default source, that is the internal tablet mic.

      This is also the case when just deploying to the tablet the provided AudioSource Qt Example. I can change the source to said headset from the dropdown menu, yet the sound level (as show by the red progress bar) is always related to the internal mic. (I verify this by gently tapping on the physical mic with a finger, headset being quite far away, and I see audio level saturation).

      I have tried to look at the source code, and actually I am confused as to where the device selection is actually forwarded to the low level OpenSLES code.

      This is what I could understand from the source code:
      a) The user queries for all available input devices via QMediaDevices::audioInputs(), which returns QAudioDevice objects. On Android, this information comes from the native AudioManager (see here and here). Devices are differentiated by their ID, and on my tablet internal mic is 19, headset is 3968.
      b) The user creates a QAudioSource instance passing the QAudioDevice that corresponds to the desired audio input. On Android, this causes the creation of a QAndroidAudioSource (see here) with the underlying device ID (say 3968 in my case)
      c) Here I am a bit lost, as the constructor of QAndroidAudioSource seems not to use the device ID information.. or, more precisely, it only compares it against a few "presets" (see here).

      Could you help me understand how this works in the low level, and how to achieve my goal of recording from a non-default source?

      Thanks,
      Arturo

      P Offline
      P Offline
      patrick521
      wrote on last edited by
      #2

      Hello, @alaurenzi

      To acquire real-time audio from a headset on an Android tablet using QAudioSource, you’ll need to specify the audio input device explicitly. By default, QAudioSource uses the system’s default audio input device, which is usually the internal microphone. To change this, you can create a QAudioSource instance with a specific QAudioDevice.

      Here’s a general outline of the steps you might follow:

      Identify the connected headset as an audio input device.
      Create a QAudioDevice instance representing the headset.
      Pass this QAudioDevice instance when constructing your QAudioSource.
      Here’s a code snippet to guide you:

      // Identify the headset as an audio input device
      QAudioDevice headsetDevice; // Replace with actual device identification

      // Set up the desired format
      QAudioFormat format;
      // Configure 'format' as needed

      // Check if the format is supported by the headset device
      if (!headsetDevice.isFormatSupported(format)) {
      qWarning() << "Desired format not supported by the headset";
      // Handle the error
      }

      // Create QAudioSource with the headset device
      QAudioSource* audioInput = new QAudioSource(headsetDevice, format, this);

      // Start recording from the headset
      audioInput->start(/* QIODevice pointer */);

      Make sure to replace headsetDevice with the actual QAudioDevice that represents your headset. You may need to iterate through the available audio input devices to find the one corresponding to your headset.

      Best Regard,
      patrick521

      @alaurenzi AARP said in Qt6 AudioSource on Android: unable to select non-default source:

      Dear developers,
      I need to acquire realtime audio from an headset on an Android tablet. After checking the documentation, QAudioSource looks the right tool for the job, and indeed to works perfectly for my application, allowing me to read the acquired audio from the provided QIODevice to then apply custom post-processing. There is though an issue, i.e. I am only able to acquire audio from the default source, that is the internal tablet mic.

      This is also the case when just deploying to the tablet the provided AudioSource Qt Example. I can change the source to said headset from the dropdown menu, yet the sound level (as show by the red progress bar) is always related to the internal mic. (I verify this by gently tapping on the physical mic with a finger, headset being quite far away, and I see audio level saturation).

      I have tried to look at the source code, and actually I am confused as to where the device selection is actually forwarded to the low level OpenSLES code.

      This is what I could understand from the source code:
      a) The user queries for all available input devices via QMediaDevices::audioInputs(), which returns QAudioDevice objects. On Android, this information comes from the native AudioManager (see here and here). Devices are differentiated by their ID, and on my tablet internal mic is 19, headset is 3968.
      b) The user creates a QAudioSource instance passing the QAudioDevice that corresponds to the desired audio input. On Android, this causes the creation of a QAndroidAudioSource (see here) with the underlying device ID (say 3968 in my case)
      c) Here I am a bit lost, as the constructor of QAndroidAudioSource seems not to use the device ID information.. or, more precisely, it only compares it against a few "presets" (see here).

      Could you help me understand how this works in the low level, and how to achieve my goal of recording from a non-default source?

      Thanks,

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alaurenzi
        wrote on last edited by
        #3

        Hi Patrick, I have already done as you say, but (on Android) this does not lead to the headset mic being actually used.
        As I explained in my post, even the provided AudioSource Qt example (which includes the logic you mentioned) fails on Android

        I have opened a bug here

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved