Skip to content

How to just get the output in Python? #246

Answered by KoljaB
Picus303 asked this question in Q&A
Discussion options

You must be logged in to vote

Yep, that's possible. You can use the on_audio_chunk callback to get the generated audio chunks directly.

Demo (which still writes to a file just to verify it works, but you can skip that if you don't need it):

import wave
import numpy as np
import torch

# Accumulators for all chunks
all_bytes = bytearray()  # Raw byte data
all_numpy_chunks = []    # List of NumPy arrays
all_tensor_chunks = []   # List of PyTorch tensors

def process_chunk(chunk_bytes):
    """
    Processes each chunk and accumulates the data for writing later.
    """
    # Convert bytes to NumPy array
    audio_data_numpy = np.frombuffer(chunk_bytes, dtype=np.int16)

    # Convert NumPy array to PyTorch tensor
    aud…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Picus303
Comment options

Answer selected by Picus303
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants