Implement audio streaming #8

Merged
0950726 merged 11 commits from feat/stream-audio into dev 2025-11-05 12:08:30 +00:00
0950726 commented 2025-10-22 13:45:05 +00:00 (Migrated from git.science.uu.nl)

Adds the AudioSender, which is used in main to send audio. It lives on a separate thread and sends its audio data asynchronously over a dedicated ZeroMQ socket.

Microphone utilities are added to utils.microphone, of which only the default microphone utility is used. The interactive utility could easily be swapped in instead.

Adds unit and integration tests for all new code, with 100% line coverage.

To test:

  • Unit tests pass (run as described in the README)
  • Run main, notice that it says "Listening with microphone ..."
  • Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level
  • Code follows standards
# coding=utf-8
import zmq

if __name__ == "__main__":
    import struct

    zmq_context = zmq.Context()

    receive_socket = zmq_context.socket(zmq.SUB)
    receive_socket.connect("tcp://localhost:5558")
    receive_socket.setsockopt_string(zmq.SUBSCRIBE, u"")

    import time
    end = time.time() + 10
    while time.time() < end:
        if not receive_socket.poll(100, flags=zmq.POLLIN):
            continue

        data = receive_socket.recv()
        samples = struct.unpack("<" + "f" * 512, data)
        avg_amp = sum(abs(s) for s in samples) / float(512)
        print("█" * int(avg_amp * 100) + " " * (100 - int(avg_amp * 100)) + " | {:.1f}%".format(avg_amp * 100))
Adds the `AudioSender`, which is used in `main` to send audio. It lives on a separate thread and sends its audio data asynchronously over a dedicated ZeroMQ socket. Microphone utilities are added to `utils.microphone`, of which only the default microphone utility is used. The interactive utility could easily be swapped in instead. Adds unit and integration tests for all new code, with 100% line coverage. To test: - [x] Unit tests pass (run as described in the README) - [x] Run main, notice that it says "Listening with microphone ..." - [x] Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level - [x] Code follows standards ```python # coding=utf-8 import zmq if __name__ == "__main__": import struct zmq_context = zmq.Context() receive_socket = zmq_context.socket(zmq.SUB) receive_socket.connect("tcp://localhost:5558") receive_socket.setsockopt_string(zmq.SUBSCRIBE, u"") import time end = time.time() + 10 while time.time() < end: if not receive_socket.poll(100, flags=zmq.POLLIN): continue data = receive_socket.recv() samples = struct.unpack("<" + "f" * 512, data) avg_amp = sum(abs(s) for s in samples) / float(512) print("█" * int(avg_amp * 100) + " " * (100 - int(avg_amp * 100)) + " | {:.1f}%".format(avg_amp * 100)) ```
0950726 commented 2025-10-22 13:45:05 +00:00 (Migrated from git.science.uu.nl)

assigned to @0950726

assigned to @0950726
8464960 commented 2025-10-24 11:41:25 +00:00 (Migrated from git.science.uu.nl)

requested review from @8464960

requested review from @8464960
8464960 commented 2025-10-24 11:53:35 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Unit tests pass (run as described in the README) as completed

marked the checklist item **Unit tests pass (run as described in the README)** as completed
8464960 commented 2025-10-24 12:12:45 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run main, notice that it says "Listening with microphone ..." as completed

marked the checklist item **Run main, notice that it says "Listening with microphone ..."** as completed
8464960 commented 2025-10-24 12:14:31 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level as completed

marked the checklist item **Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level** as completed
8464960 commented 2025-10-24 12:22:55 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Code follows standards as completed

marked the checklist item **Code follows standards** as completed
8464960 commented 2025-10-24 12:26:42 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run main, notice that it says "Listening with microphone ..." as incomplete

marked the checklist item **Run main, notice that it says "Listening with microphone ..."** as incomplete
8464960 commented 2025-10-24 12:26:47 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level as incomplete

marked the checklist item **Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level** as incomplete
8464960 commented 2025-10-24 12:26:47 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Code follows standards as incomplete

marked the checklist item **Code follows standards** as incomplete
8464960 commented 2025-10-24 12:26:48 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Unit tests pass (run as described in the README) as incomplete

marked the checklist item **Unit tests pass (run as described in the README)** as incomplete
8464960 commented 2025-10-24 12:43:24 +00:00 (Migrated from git.science.uu.nl)

Tested on WSL.
Initially, the project could not detect my microphone.
After some research, the following system packages were required:

`sudo apt install -y
libasound2 libasound2-plugins
libportaudio2 portaudio19-dev

`
After installing these, the project ran as expected.

I haven’t approved the merge request yet, since it seems that some of these dependencies might need to be added to the setup instructions or requirements documentation.

Overall, great job; I’d approve this once this issue is resolved

Tested on WSL. Initially, the project could not detect my microphone. After some research, the following system packages were required: `sudo apt install -y \ libasound2 libasound2-plugins \ libportaudio2 portaudio19-dev ` After installing these, the project ran as expected. I haven’t approved the merge request yet, since it seems that some of these dependencies might need to be added to the setup instructions or requirements documentation. Overall, great job; I’d approve this once this issue is resolved
8464960 commented 2025-10-24 12:43:53 +00:00 (Migrated from git.science.uu.nl)

left review comments

left review comments
0950726 commented 2025-10-28 09:16:33 +00:00 (Migrated from git.science.uu.nl)

Thanks, good point. I'll update the installation instructions in the README and in the error message.

I thought portaudio19-dev was the only dependency. Was that not the case for you? I'll try to reproduce this on a Windows machine at home tonight.

Thanks, good point. I'll update the installation instructions in the README and in the error message. I thought `portaudio19-dev` was the only dependency. Was that not the case for you? I'll try to reproduce this on a Windows machine at home tonight.
0950726 commented 2025-11-02 13:58:35 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

Compare with previous version

added 1 commit <ul><li>a6a12a58 - fix: remove unused qi import</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133200&start_sha=230ab5d5cc5946b5deb243bc722ec20c2c37f1ed)
0950726 commented 2025-11-02 13:59:19 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

  • 9ea44627 - fix: allow speaking text with Unicode characters

Compare with previous version

added 1 commit <ul><li>9ea44627 - fix: allow speaking text with Unicode characters</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133201&start_sha=a6a12a5886ff060a30caf72ca52ec5d20b70aa36)
0950726 commented 2025-11-02 14:01:21 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

  • 5912ac60 - docs: add installation instructions for the portaudio dependency

Compare with previous version

added 1 commit <ul><li>5912ac60 - docs: add installation instructions for the portaudio dependency</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133202&start_sha=9ea446275ed3e74c14742f04f96afe77819093ca)
0950726 commented 2025-11-02 15:12:59 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

  • fab5127c - feat: add application parameter to choose a custom microphone

Compare with previous version

added 1 commit <ul><li>fab5127c - feat: add application parameter to choose a custom microphone</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133204&start_sha=5912ac606a575ada820277c736991ec97304abb2)
0950726 commented 2025-11-02 15:16:46 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

  • 854a14bf - docs: describe `--microphone` program parameter

Compare with previous version

added 1 commit <ul><li>854a14bf - docs: describe `--microphone` program parameter</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133205&start_sha=fab5127cace233d50f9f5903d6afa4f838e75043)
0950726 commented 2025-11-02 15:35:19 +00:00 (Migrated from git.science.uu.nl)

added 1 commit

  • 8a095323 - docs: describe extra WSL installation step

Compare with previous version

added 1 commit <ul><li>8a095323 - docs: describe extra WSL installation step</li></ul> [Compare with previous version](/ics/sp/2025/n25b/pepperplus-ri/-/merge_requests/8/diffs?diff_id=133207&start_sha=854a14bf0c8395ac0b47b7d661e23e979beed823)
8464960 commented 2025-11-05 12:01:38 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Unit tests pass (run as described in the README) as completed

marked the checklist item **Unit tests pass (run as described in the README)** as completed
8464960 commented 2025-11-05 12:04:41 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run main, notice that it says "Listening with microphone ..." as completed

marked the checklist item **Run main, notice that it says "Listening with microphone ..."** as completed
8464960 commented 2025-11-05 12:08:22 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level as completed

marked the checklist item **Run the below script while main is running. You should see (for 10 seconds) bars indicating the microphone level** as completed
8464960 commented 2025-11-05 12:08:24 +00:00 (Migrated from git.science.uu.nl)

marked the checklist item Code follows standards as completed

marked the checklist item **Code follows standards** as completed
8464960 commented 2025-11-05 12:08:30 +00:00 (Migrated from git.science.uu.nl)

mentioned in commit c037eb7ec2

mentioned in commit c037eb7ec20bf853d44698d53350d1d664a28c8c
8464960 (Migrated from git.science.uu.nl) merged commit c037eb7ec2 into dev 2025-11-05 12:08:30 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: pepperplus/pepperplus-ri#8