One of the functions of my bot requires playing audio that I receive as a numpy array
So far I have gotten it to work by writing it to a temp file and playing that file
python #audio is a numpy (float32, sr=16000) with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file: temp_file_path = temp_file.name sf.write(temp_file_path, audio, samplerate=16000, format='WAV') audio_object = AudioVolume(temp_file_path) await voice_state.play(audio_object)
However I would prefer to not have to write it to a file and would rather just play it directly
So far I have tried extending the BaseAudio class so I could add bytes directly to its buffer
```python
class DAudio(BaseAudio):
def init(self, bytes) -> None:
self.buffer = AudioBuffer()
self.buffer.extend(bytes)
self.bitrate = 250
self.needs_encode = True
self.locked_stream = False
self.buffer_empty = False
@property
def audio_complete(self) -> bool:
return self.buffer_empty
def read(self, frame_size: int) -> bytes:
"""
Reads frame_size bytes of audio from the buffer.
Returns:
bytes of audio
"""
data = self.buffer.read(frame_size)
if len(data) != frame_size:
data = b""
self.buffer_empty = True
return bytes(data)
def join(self):
while not self.audio_complete:
sleep(0.15)
def cleanup(self) -> None:
pass
# In the speaking program
audio_object = DAudio(audio.tobytes())
voice_state.play(audio_object)
```This compiles without errors, and I can see the green circle around the bot in discord, but I cant hear any audio
Any help will be much appreciated. Thanks :)