Comments (4)
I'm afraid that our backend library, libsndfile, does not expose functionality for this. You could however write a wrapper around a io.BytesIO
object and open this as the ogg
file. Your wrapper could then intercept writes.
from python-soundfile.
ok. i tried many python library to do this. basically i wanna solution for
this http://stackoverflow.com/q/25469161/1263451
could you please give me at least a hint to solve this stackoverflow
question ?
On Thu, Aug 28, 2014 at 8:58 PM, Bastian Bechtold [email protected]
wrote:
I'm afraid that our backend library, libsndfile, does not expose
functionality for this. You could however write a wrapper around a
io.BytesIO object and open this as the ogg file. Your wrapper could then
intercept writes.—
Reply to this email directly or view it on GitHub
https://github.com/bastibe/PySoundFile/issues/71#issuecomment-53736912.
from python-soundfile.
Alright, so here is a simple solution. It tells you how to encode a block of audio in memory.
from io import BytesIO
import pysoundfile as sf
import numpy as np
# generate some audio data
data = np.random.randn(1000)
# create an audio "file"
file = BytesIO()
# write the audio data to the file
sf.write(data, file, 44100, format='ogg')
# get the file content
content = bytes(file.getbuffer())
Note that this creates a whole file for that chunk of data. Depending on the file format, this might carry a lot of overhead.
For example, creating a WAV file for 1000 values will take 2044 bytes (2 bytes per value, plus 44 bytes for the file header). WAV does not compress the data at all. It merely converts it to int16
. A FLAC file with the same content will take anything between 100 to 2100 bytes, depending on how well the values can be compressed (e.g. randn
values are incompressible, ones
are perfectly compressible). In realistic circumstances, don't expect more than about 2x compression. OGG will take 7319 bytes for 1000 values. However, it will only take 24371 bytes to encode 100000 values, so it will amortize it's header size for longer data lengths.
What you really want is some kind of streaming codec though. FLAC and OGG are not meant for this kind of application.
from python-soundfile.
Thank you so much for ur great time and help. i will definitely implement
this.
thanks again
On Fri, Aug 29, 2014 at 1:34 PM, Bastian Bechtold [email protected]
wrote:
Alright, so here is a simple solution. It tells you how to encode a block
of audio in memory.from io import BytesIOimport pysoundfile as sfimport numpy as np
generate some audio datadata = np.random.randn(1000)# create an audio "file"file = BytesIO()# write the audio data to the filesf.write(data, file, 44100, format='ogg')# get the file contentcontent = bytes(file.getbuffer())
Note that this creates a whole file for that chunk of data. Depending on
the file format, this might carry a lot of overhead.For example, creating a WAV file for 1000 values will take 2044 bytes (2
bytes per value, plus 44 bytes for the file header). WAV does not compress
the data at all. It merely converts it to int16. A FLAC file with the
same content will take anything between 100 to 2100 bytes, depending on how
well the values can be compressed (e.g. randn values are incompressible,
ones are perfectly compressible). In realistic circumstances, don't
expect more than about 2x compression. OGG will take 7319 bytes for 1000
values. However, it will only take 24371 bytes to encode 100000 values, so
it will amortize it's header size for longer data lengths.What you really want is some kind of streaming codec though. FLAC and OGG
are not meant for this kind of application.—
Reply to this email directly or view it on GitHub
https://github.com/bastibe/PySoundFile/issues/71#issuecomment-53848083.
from python-soundfile.
Related Issues (20)
- numpy is a dependency, but this is not declared HOT 3
- Feature request: Support interleaved stereo data HOT 4
- buffer_read doesn't work in basic test HOT 2
- Soundfile read/write wav is not symmetric with default arguments HOT 3
- module 'soundfile' has no attribute 'SoundFileRuntimeError' HOT 5
- Value Error: array is too big when loading .flac file
- soundfile crashes when trying to export long .ogg file HOT 1
- soundfile.LibsndfileError: Error opening <_io.BytesIO object at 0x0000022B81C21850>: Format not recognised. HOT 2
- Cannot suppress warnings when decoding mp3
- Cannot open Ogg FLAC file: unknown error in flac decoder HOT 1
- miniforge3/lib/python3.9/site-packages/soundfile.py", line 1229, in _init_virtual_io def vio_get_filelen(user_data): MemoryError: Cannot allocate write+execute memory for ffi.callback(). You might be running on a system that prevents this. For more information, see https://cffi.readthedocs.io/en/latest/using.html#callbacks
- Cannot write Ogg files over 96 seconds long at 44.1 kHz HOT 4
- soundfile.info does not work on mp3 HOT 2
- soundfile.LibsndfileError: <exception str() failed> HOT 6
- How to save left and right channel in separate files? HOT 1
- soundfile.LibsndfileError: Error : unknown error in flac decoder. HOT 2
- "Format not recognised." for m4a files HOT 2
- soundfile.LibsndfileError: Error opening <tempfile._TemporaryFileWrapper object at 0x7feadae59070>: Format not recognised. HOT 2
- Part of mp3 is loaded. HOT 2
- unknown error in flac decoder HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-soundfile.