Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Play, set volume and frequency of a sound with phonon
Qt 6.11 is out! See what's new in the release blog

Play, set volume and frequency of a sound with phonon

Scheduled Pinned Locked Moved General and Desktop
2 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

    Hey guys,
    I’m a beginner of this kind of programming language and I’m trying to create a program that plays a sound and sets the volume and the frequency of that sound in pyqt.
    I'm trying to use phonon with this code to play a song:

    @import sys

    import PyQt4 QtCore and QtGui modules

    from PyQt4.QtCore import *
    from PyQt4.QtGui import *
    from PyQt4.phonon import Phonon

    from mainwindow import MainWindow

    if name == 'main':

    # create application
    app = QApplication( sys.argv )
    app.setApplicationName( 'Sound project' )
    
    # create widget
    w = MainWindow()
    w.setWindowTitle( 'Sound project' )
    w.show()
    
    # connection
    QObject.connect( app, SIGNAL( 'lastWindowClosed()' ), app, SLOT( 'quit()' ) )
    
    output = Phonon.AudioOutput(Phonon.MusicCategory)
    m_media = Phonon.MediaObject()
    Phonon.createPath(m_media, output)
    m_media.setCurrentSource(Phonon.MediaSource("C:\Sound_project\Sound.mp3"))
    m_media.play()
    
    # execute application
    sys.exit( app.exec_() )@
    

    it don't give me errors but I can't hear nothing from my speakers.

    could anyone help me??
    thanks in advance you your help (and sorry for my english)

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you really sure that no error are happening ? Have a look at the music player example.

      And it's better to use forward slashes for path even on windows.

      Last thing, just check that your speakers are on, that the mixer volume is set to something and that the default output is also using your speakers (you might have an active optical output or ear speakers connected etc...)

      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

      • Login

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