In a store of music files with the Commerce File module, how can I generate an audio preview of that file? Would be perfect if I could use the Rules module for detect the adding of file and SOX utility for audio trim (for example the first 20 seconds) and attach the generated file into another field.
This sounds like an awesome companion module that could be created and would be popular. From a bit of Googling, you can use SOX or FFMPEG-PHP and the exec() command to actually trim the audio file. From there, it's just a matter of saving this audio file to a new field. I would not use rules unless you need to expose it in the interface for some reason. You could easily achieve the programmatic saving of an audio field (probably a specialized file field) using any of a number of examples out there on the web.
Found an example here: https://stackoverflow.com/questions/7884960/ffmpeg-php-code-example-to-trim-mp3-file
<?php exec('$ sox input.wav output.wav trim 0 10'); ?>