Skip to content

Commit

Permalink
added generate audio
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahawu committed May 24, 2024
1 parent af9539c commit cf0675f
Show file tree
Hide file tree
Showing 41 changed files with 93 additions and 0 deletions.
Binary file added code/generate_audio/audios/animation1.wav
Binary file not shown.
Binary file added code/generate_audio/audios/animation2.wav
Binary file not shown.
Binary file added code/generate_audio/audios/animation3.wav
Binary file not shown.
Binary file added code/generate_audio/audios/animation4.wav
Binary file not shown.
Binary file added code/generate_audio/audios/demo1.wav
Binary file not shown.
Binary file added code/generate_audio/audios/example1.wav
Binary file not shown.
Binary file added code/generate_audio/audios/example2.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack1.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack10.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack11.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack12.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack13.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack2.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack3.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack4.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack5.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack6.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack7.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack8.wav
Binary file not shown.
Binary file added code/generate_audio/audios/snack9.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv1.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv2.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv3.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv4.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv5.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv6.wav
Binary file not shown.
Binary file added code/generate_audio/audios/tv7.wav
Binary file not shown.
Binary file added code/generate_audio/components/close_door.wav
Binary file not shown.
Binary file added code/generate_audio/components/close_fridge.wav
Binary file not shown.
Binary file not shown.
Binary file added code/generate_audio/components/drop_remote.wav
Binary file not shown.
Binary file added code/generate_audio/components/empty.wav
Binary file not shown.
Binary file not shown.
Binary file added code/generate_audio/components/open_door.wav
Binary file not shown.
Binary file added code/generate_audio/components/open_fridge.wav
Binary file not shown.
Binary file not shown.
Binary file added code/generate_audio/components/pickup_remote.wav
Binary file not shown.
Binary file added code/generate_audio/components/pickup_snack.wav
Binary file not shown.
Binary file added code/generate_audio/components/step.wav
Binary file not shown.
27 changes: 27 additions & 0 deletions code/generate_audio/generate_audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import csv
from pydub import AudioSegment
from trial_actions import *

component_dir = 'components'
audio_dir = 'audios'
model_data_file = '../model_data/audios.csv'

with open(model_data_file, 'w') as f:
csvwriter = csv.writer(f)
csvwriter.writerow(['trial', 'audio'])

for trial, actions in trial_actions.items():
# generate audio file
audios = []
for action in ['empty'] + actions:
audio_file = os.path.join(component_dir, ACTION_TO_FILE[action])
audios.append(AudioSegment.from_wav(audio_file))
combined_sounds = sum(audios)
velocidad_X = 1.75
combined_sounds = combined_sounds.speedup(velocidad_X)
combined_sounds.export(os.path.join(audio_dir, f'{trial}.wav'), format = 'wav')

# record string version
if trial.startswith('snack') or trial.startswith('tv'):
csvwriter.writerow([trial, ', '.join(map(lambda x: ACTION_TO_STRING[x], actions))])
66 changes: 66 additions & 0 deletions code/generate_audio/trial_actions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
ACTION_TO_FILE = {
'close_door': 'close_door.wav',
'close_fridge': 'close_fridge.wav',
'close_television': 'close_television.wav',
'drop_remote': 'drop_remote.wav',
'empty': 'empty.wav',
'step': 'step.wav',
'idle_television': 'idle_television.wav',
'open_door': 'open_door.wav',
'open_fridge': 'open_fridge.wav',
'open_television': 'open_television.wav',
'pickup_remote': 'pickup_remote.wav',
'pickup_snack': 'pickup_snack.wav',
}

ACTION_TO_STRING = {
'close_door': 'door closed',
'close_fridge': 'fridge closed',
'close_television': 'TV turned off',
'drop_remote': 'remote dropped',
'empty': 'silence',
'step': 'step',
'idle_television': 'TV playing',
'open_door': 'door opened',
'open_fridge': 'fridge opened',
'open_television': 'TV turned on',
'pickup_remote': 'remote picked up',
'pickup_snack': 'snack picked up',
}

fridge_seq = ['open_fridge', 'pickup_snack', 'close_fridge']
spill = []
tv_seq = ['pickup_remote', 'open_television', 'idle_television', 'close_television']

trial_actions = {
# examples
'animation1': ['step'] + ['open_door'] + ['step'] * 9 + ['empty'] + fridge_seq,
'animation2': ['close_fridge', 'empty'] + ['step'] * 6 + spill + ['step'] * 4,
'animation3': ['step'] + ['open_door'] + ['step'] * 7 + ['pickup_remote', 'step', 'empty', 'open_television', 'idle_television'],
'animation4': ['idle_television', 'close_television', 'step', 'step', 'drop_remote'] + ['step'] * 6,
'demo1': ['step', 'open_door'] + ['step'] * 9 + fridge_seq + ['step'] * 10,
'example1': [],
'example2': ['step'] * 2 + ['open_door'] + ['step'] * 12 + tv_seq + ['step'] * 2 + ['drop_remote'] + ['step'] * 10 + ['close_door'] + ['step'] * 2,
# snack trials
'snack1': ['step'] * 8 + fridge_seq + ['step'] * 8,
'snack2': ['step'] * 10 + fridge_seq + ['step'] * 10,
'snack3': ['step'] * 16 + fridge_seq + ['step'] * 16,
'snack4': ['step'] * 8 + fridge_seq + ['step'] * 3 + spill + ['step'] * 5,
'snack5': ['step'] * 7 + fridge_seq + ['step'] * 2 + spill + ['step'] * 5,
'snack6': ['step'] * 10 + fridge_seq + ['step'] * 10,
'snack7': ['step'] * 10 + fridge_seq + ['step'] * 2 + spill + ['step'] * 8,
'snack8': ['step'] * 10 + fridge_seq + ['step'] * 6 + spill + ['step'] * 4,
'snack9': ['step'] * 10 + fridge_seq + ['step'] * 2 + spill + ['step'] + ['step'] * 10,
'snack10': ['step'] * 10 + fridge_seq + ['step'] * 6 + spill + ['step'] * 16,
'snack11': ['step'] * 2 + ['open_door'] + ['step'] * 9 + fridge_seq + ['step'] * 11,
'snack12': ['step'] * 11 + fridge_seq + ['step'] * 11,
'snack13': ['step'] * 2 + ['open_door'] + ['step'] * 8 + fridge_seq + ['step'] * 8 + ['close_door'] + ['step'] * 2,
# tv trials
'tv1': ['step'] * 9 + tv_seq + ['step'] * 2 + ['drop_remote'] + ['step'] * 7,
'tv2': ['step'] * 11 + tv_seq + ['step'] * 2 + ['drop_remote'] + ['step'] * 13,
'tv3': ['step'] * 9 + tv_seq + ['drop_remote'] + ['step'] * 9,
'tv4': ['step'] * 2 + ['open_door'] + ['step'] * 10 + tv_seq + ['drop_remote'] + ['step'] * 12,
'tv5': ['step'] * 9 + tv_seq + ['drop_remote'] + ['step'] * 9,
'tv6': ['step'] * 4 + ['open_door'] + ['step'] * 8 + tv_seq + ['drop_remote'] + ['step'] * 8 + ['close_door'] + ['step'] * 4,
'tv7': ['step'] * 2 + ['open_door'] + ['step'] * 6 + tv_seq + ['step'] * 2 + ['drop_remote'] + ['step'] * 10
}

0 comments on commit cf0675f

Please sign in to comment.