Documentation on PyQt Phonon backend audio effect 'speed'

五迷三道 提交于 2019-12-24 07:17:41

问题


When I look at the output of the function

Phonon.BackendCapabilities.availableAudioEffects()

I get this as one of the options:

>>> speed_effect = Phonon.BackendCapabilities.availableAudioEffects()[3]
>>> speed_effect.name()
PyQt4.QtCore.QString(u'speed')
>>> speed_effect.__doc__
'Phonon.EffectDescription()\nPhonon.EffectDescription(int, dict-of-QByteArray-QVariant)\nPhonon.EffectDescription(Phonon.EffectDescription)'

I understand that I need to insert this effect into a path connecting to my audio source file, and that implementation won't be difficult. What I don't understand is how to access options or what the functionality of this 'speed' effect is. How do I access it through the Python interface? Can I specify a playback rate (like 2x, 4x, etc., for doubling or quadrupling the speed) as an option to this?


回答1:


Well, not too many people were looking at this so I kept going and finally figured it out. Note that all of this is specific to my particular backend media player, gstreamer, for Phonon. If you have a different backend, you'll need to do some tinkering to see what effects you need to play around with.

The way this works is that you can see names and descriptions of your Phonon.Effect() options by calling the function

 from PyQt4 import QtGui, QtCore
 from PyQt4.phonon import Phonon
 list_of_backend_audio_effects = Phonon.BackendCapabilities.availableAudioEffects()

After this, I figured out which of the available effects was the gstreamer option 'speed', by doing this:

 list_of_effect_names = [str(elem.name()) for elem in list_of_backend_audio_effects]
 for iter in range(len(list_of_effect_names)):
     if list_of_effect_names[iter] == 'speed':
         effect_index = iter
         break

Finally, you need to actually edit the parameters, which has to be done by going through a data type called a QVariant. To double the speed of the audio, here's what I called:

 speed_effect = Phonon.Effect(list_of_backend_audio_effects[effect_index])
 speed_effect.setParameterValue(speed_effect.parameters()[0],QtCore.QVariant(str(2)))

In the first line, I create a new Phonon.Effect() which takes the effect description as an input (the things returned by the call the availableAudioEffects()). Then I set the parameter of this effect object (the first argument) to take the QVariant value '2' (the second argument). On my system, the default speed is '1', the min is '0.1' and the max is '40', which represents ranges of speeds between one-tenth and 40 times as fast as the regular audio file encodes.

I hope this helps some Python folks with gstreamer change speeds of audio.



来源:https://stackoverflow.com/questions/6527507/documentation-on-pyqt-phonon-backend-audio-effect-speed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!