开发者

Documentation on PyQt Phonon backend audio effect 'speed'

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 'spe开发者_开发百科ed' 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜