Comments (8)
Right, sorry that was just that one file i used for testing.. i thought it was similar to some issue that i had beforehand when it tried to "play" the header of the wave file. So everything is fine. Closing this issue now.
from pyogg.
from pyogg.
Yes, I tried those examples and managed to succeed to play a sound file. However none of the examples actually use streaming to play a file..
from pyogg.
I managed to get it kind of working but it sounds weird (a bit too fast and like with a phaser effect):
import pyaudio
from pyogg import OpusFile, OpusFileStream
def play(filename: str):
p = pyaudio.PyAudio()
stream = OpusFileStream(filename)
out_stream = p.open(format=p.get_format_from_width(width=2),
channels=stream.channels,
rate=stream.frequency,
output=True,
output_device_index=1)
print("stream.bytes_per_sample {} channels: {}, frequency:{}".format(stream.bytes_per_sample, stream.channels, stream.frequency))
while True:
# Read the next part of the stream
buf = stream.get_buffer_as_array()
# Check if we've reached the end of the stream
if buf is None:
break
out_stream.write(buf)
out_stream.stop_stream()
out_stream.close()
p.terminate()
from pyogg.
Hey there,
well, you've basically already found the solution yourself.
The only thing you need to change is how you pass on the buffer.
out_stream.write()
seems to be expecting 8-bit unsigned integer values (i.e. bytes) by default and thus, when you pass the audio data array containing 16-bit signed integers, it tries to interpret those as 8-bit, resulting in double speed and clipping.
There's two ways of changing this. Either you use the get_buffer()
function instead of the get_buffer_as_array()
function (which is called internally anyways, so it's not like you'd lose anything), or you add another argument to the out_stream.write
:
out_stream.write(buf, len(buf))
Both seem to work.
By the way, you can use stream.bytes_per_sample
instead of the constant width of 2
in the get_format_from_width()
function.
Cheers
--Zuzu_Typ--
from pyogg.
Thank you for that quick reply @Zuzu-Typ! I got it working now. :)
from pyogg.
BTW: I still get a cracking sound in the beginning of the file. I avoid it for now by just skipping the first buffer.. is that the right way to go?
from pyogg.
Thank you for that quick reply @Zuzu-Typ! I got it working now. :)
You're welcome (:
BTW: I still get a cracking sound in the beginning of the file. I avoid it for now by just skipping the first buffer.. is that the right way to go?
Hm.. I've tried two different files, but didn't get any cracking, at least I didn't notice any.
Could you please try using a different file to check if it's doing the same thing?
This is one of the two files I've tested: https://github.com/TeamPyOgg/PyOgg/blob/master/examples/left-right-demo-5s.opus
from pyogg.
Related Issues (20)
- Release latest master
- opus_file.bytes_per_sample missing
- PyOggError: File 'test.ogg' couldn't be opened or doesn't exist. Error code: -132 HOT 2
- issue loading libs when using 32bit python on 64bit windows
- How to parse ogg-stream from websocket? HOT 2
- FLAC: Word size not necessarily correct HOT 1
- AttributeError: module 'pyogg.opus' has no attribute 'opus_int32' HOT 6
- On Windows, non-ascii path breaks VorbisFile HOT 1
- Docs: include simple oneliner for apt-get install of common dependencies on Linux HOT 2
- as_array() method for OpusFile is not available HOT 6
- About how to generate .ogg/opus file when i have data(binary file) by opus_encode(...) function C language API
- How install the pyogg dependency in Ubuntu 18.04 HOT 1
- OpusFile and OpusFileStream: Open Opus files from memory. HOT 4
- Memory leaks in PyOgg?
- OggOpusWriter: Incorrect duration when sample rate is not 48kHz.
- How to install pyogg 0.7 in termux? HOT 1
- Why `bytes_per_sample` for opus file is restricted to 16 bits?
- ERROR: Could not find a version that satisfies the requirement pyogg>=0.6.14a1 HOT 2
- Problems of loading opus library
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 pyogg.