New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use directly in memory, instead of via files, possible? #6
Comments
I thought about this, and I decided it's out of scope for this library. I'd suggest simply writing the audio back to disk and then using pysox on the file. I realize this isn't ideal, but I think to do this in pysox without saving the audio first requires a lot of command line magic. That said, if you find a clean way to do it, I'm happy to look at the PR. |
Not that this solves the issue of taking an i/o hit, but in the meanwhile a safe way to concatenate operations is to use with tempfile.NamedTemporaryFile(suffix='.wav') as tmp:
tfm = sox.Transformer()
tfm.trim(0, 5)
tfm.build(infile, tmp.name)
cbn = sox.Combiner()
cbn.build([tmp.name, tmp.name], outfile, 'concatenate') The downside is that since sox requires a filename, you need to use a Right now the workaround is by changing the logger level: logger = logging.getLogger()
logger.setLevel('CRITICAL')
with tempfile.NamedTemporaryFile(suffix='.wav') as tmp:
tfm = sox.Transformer()
tfm.trim(0, 5)
tfm.build(infile, tmp.name)
cbn = sox.Combiner()
cbn.build([tmp.name, tmp.name], outfile, 'concatenate')
logger.setLevel('WARNING') Or if you just want to suppress all logging you can do |
@justinsalamon, @rabitt, I've published a lightweight SoX effects wrapper (reverb, phaser, delay, etc.) that pipes NumPy ndarrays over stdin/stdout instead of creating extra I/O load with tempfiles. Maybe you can use bits of it in pysox: https://github.com/carlthome/python-audio-effects |
@justinsalamon can you open a separate issue about optionally disabling the overwrite warning? |
@carlthome Looks awesome! I plan to include this feature when I bump to v1.3 |
|
I must admit that it would be very useful. I need this transformations on the fly, holding everything in RAM, so saving to a disk and then again loading to python is inefficient. |
I'll try porting @carlthome 's work to pysox, It'd be nice if you guys could give me some pointers on how you'd wish it to be implemented. I'd personally see it as another method on the transformer and combine class to output a numpy ndarray, such as To input ndarray soundfiles, i guess this could be just some slight modifications on the args of the |
Sound great! I'd love to get rid of my package entirely and have pysox be the only SoX Python wrapper if possible. |
@carlthome I do not think that solving this issue would require having all of librosa as a dependency. Since it's purely a matter of I/O, |
@hadware -
I agree that what makes the most sense is to have a separate function
Yes, as far as I can tell it's doable by changing the input and output filename to the In terms of capturing the audio data from stdout, I think everything is already in place, but if you run into issues, this is where the problem is likely to be. Let me know if you need any help! |
I'm going to give addressing this issue a shot, mostly by trying to port @carlthome's pysndfx fix into this library. Do people have the bandwidth for a PR for this soon (hopefully)? Looking over the comments here, I believe such a change would require adding |
Is it possible to use the |
Would it be possible to input audio as ndarray:s into pysox directly as well as files from disk? Why I'm asking is because I'm using librosa for onset detection, and thus already have the audio loaded, but would still like to apply some audio effects and stuff afterwards.
Like maybe the constructors could do a type check, and build() could return the destination audio or something?
I realize this adds extra complexity to pysox (like having librosa as a dependency or similar) which is intended to be a clean wrapper around SoX, so I get if it's deemed out of scope. Just asking!
The text was updated successfully, but these errors were encountered: