Skip to content

Conversation

@cclauss
Copy link
Contributor

@cclauss cclauss commented Jun 18, 2025

Installing the third-party Whole Architecture Verification module https://pypi.org/project/Wave is breaking our builds.

The Python Standard Library module wave has an API that corresponds to:

# Save audio file
wf = wave.open("recording.wav", "wb")
wf.setnchannels(1)
wf.setsampwidth(pyaudio.PyAudio().get_sample_size(pyaudio.paInt16))
wf.setframerate(44100)
wf.writeframes(b''.join(frames))
wf.close()

Therefore, we should stop doing pip install wave and instead use the Standard Library.

The docs at https://ardupilot.org/mavproxy/docs/modules/chat.html#prerequisites must also be modified.

@rmackay9 Your review, please.

@cclauss cclauss changed the title wave is a Python Standard Library module wave is a Python Standard Library module Jun 18, 2025
Installing the third-party ___Whole Architecture Verification___ module https://pypi.org/project/Wave is [breaking our builds](https://github.com/ArduPilot/MAVProxy/actions/workflows/windows_build.yml).

The Python Standard Library module  [`wave`](https://docs.python.org/3/library/wave.html) has an API that corresponds to:
https://github.com/ArduPilot/MAVProxy/blob/a45549f9bcb09603be1507c260de2bafe516212a/MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py#L72-L78

Therefore, we should stop doing `pip install wave` and instead use the Standard Library.

The docs at https://ardupilot.org/mavproxy/docs/modules/chat.html#prerequisites must also be modified.

% `git grep wave`
@cclauss cclauss force-pushed the wave-is-a-Python-Standard-Library-module branch from ba3b320 to 6cf5b33 Compare June 18, 2025 13:35
cclauss added a commit to cclauss/ardupilot_wiki that referenced this pull request Jun 18, 2025
These changes should be made together with:
* ArduPilot/MAVProxy#1588
@peterbarker
Copy link
Contributor

This looks good to me - was it tested as working with the standard module?

@cclauss
Copy link
Contributor Author

cclauss commented Jun 19, 2025

was it tested as working with the standard module?

Yes, I ran the full test suite that was included in:

(Sorry, only joking...)


This is a Windows app, and I have no access to Windows, but I did...

% pip install wave # fails!

On macOS, I created a new test_record_audio.py file.

#!/usr/bin/env -S uv run --script

# /// script
# requires-python = ">=3.9"
# dependencies = [
#     "openai",
#     "pyaudio",
# ]
# ///

Paste MAVProxy/modules/mavproxy_chat/chat_voice_to_text.py here.

if __name__ == "__main__":
    from pathlib import Path

    filename = chat_voice_to_text().record_audio()
    assert filename == "recording.wav"
    filepath = Path(__file__).parent / filename
    assert filepath.exists()
    assert filepath.is_file()
    print(f"{filepath.stat() = }")
    print(f"Size of {filepath} is {filepath.stat().st_size:,} bytes.")

Make a change to the code:

-        while not stop_recording[0]:
+        # while not stop_recording[0]:
+        print("chat: recording audio for 5 seconds...")
+        for _ in range(0, int(44100 / 1024 * 5)):  # record for 5 seconds

% uv run test_record_audio.py # Say something when the recording starts!

  • Or % pipx run test_record_audio.py
chat: recording audio for 5 seconds...
filepath.stat() = os.stat_result(st_mode=33188, st_ino=291196442, st_dev=16777231, st_nlink=1, st_uid=501, st_gid=20, st_size=440364, st_atime=1750304146, st_mtime=1750304146, st_ctime=1750304146)
Size of recording.wav is 440,364 bytes.

% open recording.wav -a GarageBand
Hit the play button...

This runs all wave-related lines of code and produces audible proof that it works.

@rmackay9
Copy link
Contributor

The author ping'd me about this so I've added it to the EUDevCall. I'm not really qualified to review the PR

@cclauss
Copy link
Contributor Author

cclauss commented Jun 25, 2025

@peterbarker Time ran out on today's EUDevCall which only focused on the main repo.

Are you satisfied with the testing above? What are the todos here? This does fix broken builds.

@stephendade
Copy link
Contributor

I've had a look at this PR. To clarify any confusion:

The pypi wave library is not used in MAVProxy. This library is the "Whole architecture verification" and has nothing to do with reading .wav files.

Reading .wav files is handled by the built-in wave library in Python.

It is an annoying name-collision between the pypi package and built-in libraries.

I've tested the PR and it works fine.

@peterbarker peterbarker merged commit 742f430 into ArduPilot:master Jun 26, 2025
2 checks passed
@peterbarker
Copy link
Contributor

@peterbarker Time ran out on today's EUDevCall which only focused on the main repo.

Ah, sorry. We usually only do focus on the main repo, it's actually very rare that we remember to go and check other repos for DevCallEU!

Are you satisfied with the testing above? What are the todos here? This does fix broken builds.

Our Windows maintainer tested it as good - so I've merged it, thanks!

@cclauss cclauss deleted the wave-is-a-Python-Standard-Library-module branch June 26, 2025 01:33
cclauss added a commit to cclauss/ardupilot_wiki that referenced this pull request Jul 5, 2025
These changes should be made together with:
* ArduPilot/MAVProxy#1588
Hwurzburg pushed a commit to ArduPilot/ardupilot_wiki that referenced this pull request Jul 5, 2025
These changes should be made together with:
* ArduPilot/MAVProxy#1588
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants