Skip to content

Custom Audio Source #699

Open
Open
@parkerbjur

Description

@parkerbjur

I am trying to make a custom audio source class that will accept any Raw Audio. I have a stream class in my source class that can be written to by things outside of the class and then a read function for the recognizer to use. The problem is my buffer keeps running out. How do the other audio sources avoid this problem as it seems the Microphone Source has an unlimited amount of data available? Or at least whenever read is called on Microphone Source something is returned. Here is the implementation of my RawStream. Any advice would be appreciated.

class RawStream(object):
        def __init__(self, sample_width=2):
            self.sample_width = sample_width
            self.sampleDataType = sampleDataTypes[sample_width]
            self.stream = np.array([], dtype=self.sampleDataType)

        # read size bytes from the beginning of stream if possible, or return None otherwise
        def read(self, size):
            data = self.stream[:size]
            self.stream = self.stream[size:]
            return data

        def write(self, data):
            data = np.frombuffer(data, dtype=self.sampleDataType)
            self.stream = np.concatenate((self.stream, data))

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions