record_sound()
  • 1 Minute to read

record_sound()


Article summary

This function records a sound to a path based on the duration given.

Arguments

ArgumentsTypeDefault ValueDescription
durationfloat60.0Duration of recording (sec) in float.
pathstrPath to which sound is recorded.
callback_finishfunctionNoneIf you define a finish callback, it will be called when the movement finishes or is interrupted.
waitboolTrueIf True, the code will be blocked until the end of the sound.

Return

TypeDescription
SoundDataRecorded data as SoundData object.

Exceptions

  • RayaSoundErrorRecording
  • RayaNeedCallback

See the complete sound exceptions.
See the general exceptions.

Usage example

from raya.application_base import RayaApplicationBase
from raya.controllers.sound_controller import SoundController


DURATION = 10.0
NAME_RECORD = 'dat:record.wav'


class RayaApplication(RayaApplicationBase):

    async def setup(self):
        self.sound: SoundController = await self.enable_controller('sound')


    async def loop(self):
        self.log.warn((
                f'Recording for {DURATION} seconds in the file {NAME_RECORD}'
            ))
        response = await self.sound.record_sound(
                duration=DURATION,
                path=NAME_RECORD,
                wait=True,
            )
        print(response)
        self.finish_app()


    async def finish(self):
        self.log.info(f'Hello from finish()')



Was this article helpful?

What's Next