-
Notifications
You must be signed in to change notification settings - Fork 10.1k
store mic audio with toggle #35595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
store mic audio with toggle #35595
Changes from all commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
ea0faea
store/send mic audio with toggle
Quantizr 053e87b
script to extract audio from logs
Quantizr 7baa1f6
change description and add translation placeholders
Quantizr bd230b3
microphone icon
Quantizr dfcc7c0
apply toggle in loggerd
Quantizr 54297ef
add legnth and counter
Quantizr df9759c
startFrameIdx counter
Quantizr 93c7aa1
Revert "change description and add translation placeholders"
Quantizr 861162c
send mic data first and then calc
Quantizr 625c1b9
restore changed description/icon after revert
Quantizr a5d4b00
adjust fft samples to keep old time window
Quantizr e358d4e
remove extract_audio.py since audio is now stored in qcam isntead of …
Quantizr e9b801a
qt microphone recording icon
Quantizr 5a2f6e3
Revert "remove extract_audio.py since audio is now stored in qcam isn…
Quantizr 6abf559
move extract_audio script and output file by default
Quantizr eb3d9b0
remove length field
Quantizr f5913c1
recording indicator swaps sides based on lhd/rhd
Quantizr a73c6ae
use record icon from comma body
Quantizr a4b3338
Update toggle description
Quantizr 569b104
update raylib toggle desc cause I did earlier
Quantizr d1606b6
microphone --> soundPressure, audioData --> rawAudioData
Quantizr 2fe607c
cleanup unused var
Quantizr ad6f946
update README
Quantizr 7c3addc
sidebar mic indicator instead of annotated camera
Quantizr 1017876
improve logic readability
Quantizr a9d093c
remove startFrameIdx and sequenceNum
Quantizr 9ffcf9b
use Q_PROPERTY/setProperty so that update() is actually called on val…
Quantizr 4a73b8c
specify old id for SoundPressure
Quantizr 98c24cf
fix typo
Quantizr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env python3 | ||
import os | ||
import sys | ||
import wave | ||
import argparse | ||
import numpy as np | ||
|
||
from openpilot.tools.lib.logreader import LogReader, ReadMode | ||
|
||
|
||
def extract_audio(route_or_segment_name, output_file=None, play=False): | ||
lr = LogReader(route_or_segment_name, default_mode=ReadMode.AUTO_INTERACTIVE) | ||
audio_messages = list(lr.filter("rawAudioData")) | ||
if not audio_messages: | ||
print("No rawAudioData messages found in logs") | ||
return | ||
sample_rate = audio_messages[0].sampleRate | ||
|
||
audio_chunks = [] | ||
total_frames = 0 | ||
for msg in audio_messages: | ||
audio_array = np.frombuffer(msg.data, dtype=np.int16) | ||
audio_chunks.append(audio_array) | ||
total_frames += len(audio_array) | ||
full_audio = np.concatenate(audio_chunks) | ||
|
||
print(f"Found {total_frames} frames from {len(audio_messages)} audio messages at {sample_rate} Hz") | ||
|
||
if output_file: | ||
if write_wav_file(output_file, full_audio, sample_rate): | ||
print(f"Audio written to {output_file}") | ||
else: | ||
print("Audio extraction canceled.") | ||
if play: | ||
play_audio(full_audio, sample_rate) | ||
|
||
|
||
def write_wav_file(filename, audio_data, sample_rate): | ||
if os.path.exists(filename): | ||
if input(f"File '{filename}' exists. Overwrite? (y/N): ").lower() not in ['y', 'yes']: | ||
return False | ||
|
||
with wave.open(filename, 'wb') as wav_file: | ||
wav_file.setnchannels(1) # Mono | ||
wav_file.setsampwidth(2) # 16-bit | ||
wav_file.setframerate(sample_rate) | ||
wav_file.writeframes(audio_data.tobytes()) | ||
return True | ||
|
||
|
||
def play_audio(audio_data, sample_rate): | ||
try: | ||
import sounddevice as sd | ||
|
||
print("Playing audio... Press Ctrl+C to stop") | ||
sd.play(audio_data, sample_rate) | ||
sd.wait() | ||
except KeyboardInterrupt: | ||
print("\nPlayback stopped") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description="Extract audio data from openpilot logs") | ||
parser.add_argument("-o", "--output", help="Output WAV file path") | ||
parser.add_argument("--play", action="store_true", help="Play audio with sounddevice") | ||
parser.add_argument("route_or_segment_name", nargs='?', help="The route or segment name") | ||
|
||
if len(sys.argv) == 1: | ||
parser.print_help() | ||
sys.exit() | ||
args = parser.parse_args() | ||
|
||
output_file = args.output | ||
if not args.output and not args.play: | ||
output_file = "extracted_audio.wav" | ||
|
||
extract_audio(args.route_or_segment_name.strip(), output_file, args.play) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.