Streaming using the Python SDK
Streaming using the SDK
Install the Behavioral Signals SDK from PyPI:
pip install behavioralsignalsThen you can easily start a stream as such:
from behavioralsignals import Client, StreamingOptions
from behavioralsignals.utils import make_audio_stream, print_results
client = Client()
audio_stream, sample_rate = make_audio_stream(
"audio.wav",
chunk_size=0.25,
)
options = StreamingOptions(
sample_rate=sample_rate,
encoding="LINEAR_PCM",
)
for result in client.behavioral.stream_audio(
audio_stream=audio_stream,
options=options,
):
print_results(result.results)Client() reads your credentials from the BEHAVIORALSIGNALS_CID and BEHAVIORALSIGNALS_API_KEY environment variables (see setup).
chunk_size is specified in seconds, so 0.25 corresponds to 250 ms.
- The
client.behavioral.stream_audiomethod expects anIterator[bytes]that corresponds to the bytes of the audio stream. - The
StreamingOptionsdefine thesample rateandencodingof the streamed audio.
Also check the 🎤 streaming from microphone and 📁 streaming from file examples in the Github repo
Updated 6 days ago
Did this page help you?

