Skip to content

Add example: record G1 microphone stream to WAV on PC#133

Open
nmandic78 wants to merge 1 commit intounitreerobotics:masterfrom
nmandic78:feat/g1-mic-record-example
Open

Add example: record G1 microphone stream to WAV on PC#133
nmandic78 wants to merge 1 commit intounitreerobotics:masterfrom
nmandic78:feat/g1-mic-record-example

Conversation

@nmandic78
Copy link

What

Adds a new example that receives the G1 microphone audio stream via UDP multicast and saves it as a WAV file on an external PC.

How

  • Introduces record_pcm_multicast_to_wav() helper in example/g1/audio/wav.py for receiving PCM audio via UDP multicast and writing WAV output
  • Adds g1_audio_mic_record_udp.py example that uses this helper

Usage

python g1_audio_mic_record_udp.py <network_interface_ip> [seconds] [output_wav]

### Example
python g1_audio_mic_record_udp.py 192.168.123.99 5 /tmp/g1_record.wav

### notes
- No API changes, examples only
- Intended for setups where ASR / voice processing runs on an external PC
- Output format: 16 kHz, mono, PCM WAV
- Tested on Ubuntu 22.04 with G1 EDU

@ivinesTR
Copy link

Hello!

I was trying to run your script directly on robot's PC4, and it seems that micros are not running:

unitree@ubuntu:~/unitree_sdk2_python/example/g1/audio$ python g1_audio_mic_record_udp.py 192.168.123.164 5 /tmp/g1_record.wav
[INFO] multicast group=239.168.123.161 port=5555 iface_ip=192.168.123.164
[INFO] recording 5.0s -> target_bytes=160000
[INFO] start record!
Traceback (most recent call last):
File "/home/unitree/unitree_sdk2_python/example/g1/audio/wav.py", line 210, in record_pcm_multicast_to_wav
data, _ = sock.recvfrom(recv_buf_bytes)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "g1_audio_mic_record_udp.py", line 25, in
main()
File "g1_audio_mic_record_udp.py", line 14, in main
record_pcm_multicast_to_wav(
File "/home/unitree/unitree_sdk2_python/example/g1/audio/wav.py", line 212, in record_pcm_multicast_to_wav
raise RuntimeError("Timed out waiting for mic packets. Stream may be off or interface join is wrong.")
RuntimeError: Timed out waiting for mic packets. Stream may be off or interface join is wrong.

My robot's Ip is the 192.168.123.164 as configured as default.

Did you find this before? I suppose is an error regarding the configuration or some initialization.

@ivinesTR
Copy link

I've already solved it switching the robot to wake up mode:

unitree app > connected to the g1 in ap mode > Device > Data > Voice Assistant > Wake-up Conversation Mode

@nmandic78
Copy link
Author

Glad you found a method to start streaming. It must have been on on our G1 as I assumed it is by default always on after robot boot.
Not with G1 at the moment, but will explore next week how to initiate from python using ROS2 publish.
This should be done with something like 'ros2 topic echo /api/audiohub/request' on PC2 (G1 SSH) and then switching 'Wake-up Conversation Mode' from mobile app. We then note api_id and parameters needed to initiate streaming.

But now you have it and it should be permanent as set once from app (at least it is on on our G1)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments