Skip to content

Commit

Permalink
Improving sound quality a bit, reverting changes to play audio files
Browse files Browse the repository at this point in the history
  • Loading branch information
danilo-pejovic committed Mar 4, 2024
1 parent 3337c25 commit 8ed3aac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
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
23 changes: 1 addition & 22 deletions rae_sdk/rae_sdk/robot/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ament_index_python import get_package_share_directory
import base64
import ffmpeg

from rae_msgs.srv import PlayAudio


Expand Down Expand Up @@ -35,28 +34,10 @@ def __init__(self, ros_interface):
log.info("Audio Controller ready")


def play_audio_file(self, audio_file_path, delete_after_play=False):
"""
Play an audio file and optionally delete it after playback.
Args:
audio_file_path (str): Path to the audio file.
delete_after_play (bool, optional): Whether to delete the audio file after playback. Defaults to False.
Returns:
res: Response from the service call.
"""
def play_audio_file(self, audio_file_path):
req = PlayAudio.Request()
req.file_location = audio_file_path
res = self._ros_interface.call_async_srv('/play_audio', req)

# Delete the file if requested
if delete_after_play:
try:
os.remove(audio_file_path)
except OSError as e:
print(f"Error deleting file: {e}")

return res

def save_recorded_sound(self, audio_data, output_file="/app/mic_recording.wav"):
Expand All @@ -81,8 +62,6 @@ def save_recorded_sound(self, audio_data, output_file="/app/mic_recording.wav"):
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')
res = self.play_audio_file(horn_path)
Expand Down

0 comments on commit 8ed3aac

Please sign in to comment.