Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Try to change default audio output device on MacOS
Qt 6.11 is out! See what's new in the release blog

Try to change default audio output device on MacOS

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi,

    I tried to change the default audio output device on MacOS.

    Here is my code:

    from PySide6 import QtMultimedia
    
    devices = QtMultimedia.QMediaDevices.audioOutputs()
    device_list = {}
    number = 1
    for device in devices:
        default = " "
        device_list[str(number)] = QtMultimedia.QAudioDevice(device)
        if device.isDefault():
            default = "#"
        print(f"{default} {number} - {device.description()}")
        number += 1
        
    choice = input("> ")
    
    QtMultimedia.QAudioOutput.setDevice(device_list[choice])
    

    I have tried multiple way to accomplish that.
    When I try to use QtMultimedia.QAudioOutput.setDevice() I got the following error.

    TypeError: descriptor 'setDevice' for 'PySide6.QtMultimedia.QAudioOutput' objects doesn't apply to a 'PySide6.QtMultimedia.QAudioDevice' object
    

    In the documentation, setDeviceneed a PySide6.QtMultimedia.QAudioDevice object. And this is what I use.

    What am I doing wrong? What have I not understood?

    Thanks

    SGaistS 1 Reply Last reply
    0
    • ? A Former User

      Hi,

      I tried to change the default audio output device on MacOS.

      Here is my code:

      from PySide6 import QtMultimedia
      
      devices = QtMultimedia.QMediaDevices.audioOutputs()
      device_list = {}
      number = 1
      for device in devices:
          default = " "
          device_list[str(number)] = QtMultimedia.QAudioDevice(device)
          if device.isDefault():
              default = "#"
          print(f"{default} {number} - {device.description()}")
          number += 1
          
      choice = input("> ")
      
      QtMultimedia.QAudioOutput.setDevice(device_list[choice])
      

      I have tried multiple way to accomplish that.
      When I try to use QtMultimedia.QAudioOutput.setDevice() I got the following error.

      TypeError: descriptor 'setDevice' for 'PySide6.QtMultimedia.QAudioOutput' objects doesn't apply to a 'PySide6.QtMultimedia.QAudioDevice' object
      

      In the documentation, setDeviceneed a PySide6.QtMultimedia.QAudioDevice object. And this is what I use.

      What am I doing wrong? What have I not understood?

      Thanks

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You are calling an instance method on a class. You need to call setDevice on the instance of QAudioOutput that you are going to use in your application.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      ? 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        You are calling an instance method on a class. You need to call setDevice on the instance of QAudioOutput that you are going to use in your application.

        ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #3

        I have tried to create an instance of QAudioOutput with the device as parameter, but setDevice needs the device too, whatever.
        And in this case nothing happend.

        Do you have any example ?

        SGaistS 1 Reply Last reply
        0
        • ? A Former User

          I have tried to create an instance of QAudioOutput with the device as parameter, but setDevice needs the device too, whatever.
          And in this case nothing happend.

          Do you have any example ?

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What exactly did you do ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          ? 1 Reply Last reply
          0
          • SGaistS SGaist

            What exactly did you do ?

            ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            I think I made a mistake.
            I try to change the default audio output for the entire system, not for my application.

            My application as no audio. His purpose is only for changing audio output for all application.

            SGaistS 1 Reply Last reply
            0
            • ? A Former User

              I think I made a mistake.
              I try to change the default audio output for the entire system, not for my application.

              My application as no audio. His purpose is only for changing audio output for all application.

              SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Then you will have to use system APIs, if any exists, for that kind of use case. Changing system settings is outside the scope of Qt.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              ? 1 Reply Last reply
              0
              • SGaistS SGaist

                Then you will have to use system APIs, if any exists, for that kind of use case. Changing system settings is outside the scope of Qt.

                ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #7

                Thanks for your help.

                1 Reply Last reply
                0
                • System has marked this topic as solved on

                • Login

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