-
Notifications
You must be signed in to change notification settings - Fork 230
How to feed a stream of audio into Precise
Matthew D. Scholefield edited this page Apr 19, 2018
·
1 revision
Sometimes you want to run precise on a stream of audio that comes from a source other than the microphone. To do this, we'll need to write a little Python code. The basis is using Precise's ReadWriteStream
to transfer data between the source of the data and Precise's engine. Here's the code to do it:
stream = ReadWriteStream()
runner = PreciseRunner(
PreciseEngine('.venv/bin/precise-engine', 'my-model.pb.or.net'),
stream=stream, on_activation=lambda: print('Activated!')
)
runner.start()
As you can see, there's a constructor argument that we use to pass in the ReadWriteStream
. Now you can get your bytes from the source of your data and pass them in like this:
while True:
audio_chunk = read_bytes_from_network() # Example data: b'\xx\a0\22\26\46\c5\d5\f0'
stream.write(audio_chunk)
If you want to stream the audio over a network using sockets, you can use this Precise server-client code here. This will allow you to run the server once with multiple clients and listen for the wake word on each input stream.