Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Audio Source #699

Open
parkerbjur opened this issue Jun 29, 2023 · 1 comment
Open

Custom Audio Source #699

parkerbjur opened this issue Jun 29, 2023 · 1 comment

Comments

@parkerbjur
Copy link

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))
@Spricmic
Copy link

Hey, I was wondering if you have found a solution to this.
Currently, I'm looking for a solution to use the speech_recognition package, with my source being a ROS2 /audio topic that I would like to convert to text.

If you have any pointers for me, it would also be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants