Home | Tutorials | Wiki | Issues
Ask Your Question
0

How to playback audio (.WAV file) by using openal.world file?

asked 2017-08-01 04:55:10 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

The openal.world file includes <audio_source> and <audio_sink> for two models respectively. the collision could trigger audio playback. the original file is below:

<?xml version="1.0" ?>
<sdf version="1.5">
  <world name="default">
    <include>
      <uri>model://ground_plane</uri>
    </include>
    <include>
      <uri>model://sun</uri>
    </include>
    <audio>
      <device>default</device>
    </audio>
    <model name="box">
      <pose>0 0 10.5 0 0 0</pose>
      <link name="link">
        <collision name="collision">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <box>
              <size>1 1 1</size>
            </box>
          </geometry>
          <material>
            <script>Gazebo/WoodPallet</script>
          </material>
        </visual>
        <audio_source>
          <uri>file://media/audio/cheer.mp3</uri>
          <pitch>2.0</pitch>
          <gain>1.0</gain>
          <loop>false</loop>
          <contact>
            <collision>collision</collision>
          </contact>
        </audio_source>
      </link>
    </model>
    <model name="sphere">
      <pose>0 1.5 0.5 0 0 0</pose>
      <link name="link">
        <audio_sink />
        <collision name="collision">
          <geometry>
            <sphere>
              <radius>0.5</radius>
            </sphere>
          </geometry>
        </collision>
        <visual name="visual">
          <geometry>
            <sphere>
              <radius>0.5</radius>
            </sphere>
          </geometry>
          <material>
            <script>Gazebo/WoodPallet</script>
          </material>
        </visual>
      </link>
    </model>
  </world>
</sdf>

I don't know why I can't hear any sound after one object collide with another object, and I have tried to move the object around the plane, but it still has no sound. PS: the headset is no problem.

It would be grateful if someone can tell me how to play audio files in Gazebo by using OpenAL.

Thanks in advance.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-01 20:26:18 -0500

OpenAL only works if you build Gazebo from source and have the required dependencies installed. See this.

edit flag offensive delete link more

Comments

Gazebo8, Ubuntu 16.04. When I am building Gazebo8 from source. [ 17%] Linking CXX shared library libgazebo_common.so /usr/bin/ld: /usr/local/lib/libavcodec.a(allcodecs.o): relocation R_X86_64_32 against `ff_h263_vaapi_hwaccel' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libavcodec.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status gazebo/common/CMakeFiles/gazebo_common.dir/build.make:1260: recipe for target 'gazebo/common/libgazeb

Daniel.T gravatar imageDaniel.T ( 2017-08-03 04:12:15 -0500 )edit

(follow above comment). Hello Chapulina, thank you very much. I followed that procedure, but I couldn't install gazebo8 from source successful. I guess I should use Gazebo7 with Ubuntu 14.04, and I am still trying. Do you have any idea?

Daniel.T gravatar imageDaniel.T ( 2017-08-03 04:18:54 -0500 )edit

Have you installed these: libswscale-dev libavutil-dev libavcodec-dev libavformat-dev

chapulina gravatar imagechapulina ( 2017-08-03 09:57:46 -0500 )edit

Yes, I have installed these packages, and just tried it again, it's still unsuccessful. The error reports: [ 23%] Building CXX object deps/opende/CMakeFiles/gazebo_ode.dir/src/joints/slider.cpp.o [ 23%] Building CXX object deps/opende/CMakeFiles/gazebo_ode.dir/src/joints/universal.cpp.o [ 23%] Linking CXX shared library libgazebo_ode.so [ 23%] Built target gazebo_ode Makefile:160: recipe for target 'all' failed make: *** [all] Error 2 Should I use Gazebo7 with Ubuntu 14.04?

Daniel.T gravatar imageDaniel.T ( 2017-08-04 02:26:38 -0500 )edit

Thank you very much! I solved the problem. Under Ubuntu 14.04, build Gazebo7 from source according to Chapulina's suggestion, and follow that procedure, you will hear the sounds after you launched openal.world. However, it is still unsuccessful when I build Gazebo8 from source under Ubuntu 16.04.I hope someone could fix this later. So far, my suggestion is to use Gazebo7 with Ubuntu 14.04.

Daniel.T gravatar imageDaniel.T ( 2017-08-04 05:23:13 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-08-01 04:55:10 -0500

Seen: 47 times

Last updated: Aug 01