Skip to content
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

Mic recording #74

Merged
merged 8 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ RUN apt-get update && apt-get -y install --no-install-recommends \
libsndfile1-dev \
libsndfile1

RUN pip3 install openai
RUN pip3 install openai ffmpeg-python

ENV WS=/ws
RUN mkdir -p $WS/src
Expand Down
2 changes: 1 addition & 1 deletion rae_hw/src/peripherals/speakers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void SpeakersNode::play_wav(const char* wav_file) {
int32_t* buffer_wav = new int32_t[BUFFER_SIZE * sfinfo.channels]; // Use int32_t for 32-bit format
sf_count_t readCount;

const float gain = 64.0f; // Adjust this factor for desired gain
const float gain = 16.0f; // Adjust this factor for desired gain

while((readCount = sf_readf_int(file, buffer_wav, BUFFER_SIZE)) > 0) {
// Apply gain to the samples
Expand Down
28 changes: 27 additions & 1 deletion rae_sdk/rae_sdk/robot/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import random
import logging as log
from ament_index_python import get_package_share_directory

import base64
import ffmpeg
from rae_msgs.srv import PlayAudio


Expand Down Expand Up @@ -38,6 +39,31 @@ def play_audio_file(self, audio_file_path):
req.file_location = audio_file_path
res = self._ros_interface.call_async_srv('/play_audio', req)
return res

def save_recorded_sound(self, audio_data, output_file="/app/mic_recording.wav"):
"""
Decode the Base64 audio data and save it as a WAV file.

Attributes
----------
audio_data (str): Base64 encoded audio data.
output_file (str, optional): Path to save the WAV file. Defaults to "/app/output.wav".


"""
# Decode Base64 data
binary_data = base64.b64decode(audio_data)

# Convert WebM to WAV using ffmpeg
output, _ = (
ffmpeg.input('pipe:', format='webm')
.output('pipe:', format='wav')
.run(input=binary_data, capture_stdout=True, capture_stderr=True)
)

# Write the output to the specified WAV file
with open(output_file, 'wb') as wave_file:
wave_file.write(output)

def honk(self):
horn_path = os.path.join(self._assets_path, 'sfx', 'horn.mp3')
Expand Down
Loading