nicoaudio¶
The nicoaudio package contains classes to control the audio interface of the NICO.
AudioPlayer¶
The AudioPlayer class manages the playback and manipulation of audio.
- class nicoaudio.AudioPlayer.AudioPlayer(filename, start=0, duration=None, audio_device=None)¶
Bases:
objectThe AudioPlayer class allows asynchronous playback of (a segment of) a single audio file.
- _playback()¶
Playback function for thread. Plays a segment until running is set to false or end is reached
- property duration¶
Duration of the loaded audio segment
- Returns
Duration in seconds
- Return type
float
- property filename¶
Name of the loaded file
- Returns
filename
- Return type
str
- pause()¶
Stops playback of the audio segment
- pitch(octaves)¶
Shifts pitch in octaves (this affects the speed)
- Parameters
pitch (float) – Pitch in octaves by which to shift the output (this affects the speed)
- play(volume=1.0)¶
Starts playback of the audio segment from its beginning
- Parameters
percentage (float) – Volume [0.0, 1.0]
- property position¶
Current playback position
- Returns
Position in seconds
- Return type
float
- resume()¶
Continues playback of the file from where it was previously stopped.
- speed(speed)¶
Adjusts speed to given percentage without changing pitch
- Parameters
speed (float) – Percentage to increase/decrease speed without changing pitch
- property volume¶
Percentage of volume
- Returns
Volume [0.0, 1.0]
- Return type
float
- nicoaudio.AudioPlayer.get_pulse_device()¶
Detects pulse device
- Returns
id of the pulse device
- Return type
int
AudioRecorder¶
The AudioRecorder class manages the caption of audio from the microphones on the NICO robot.
- class nicoaudio.AudioRecorder.AudioRecorder¶
Bases:
object- startMicrophonesRecording(filename='sound.wav', type='wav', samplerate=44100, channels=(True, True))¶
Starts the microphone recording to a given file
- Parameters
filename (str) – Name of target file
type (str) – Type of recording (only wav is supported as of writing)
samplerate (int) – Target samplerate
channels (tuple(bool, bool)) – requested channels (left,right)
- stopMicrophonesRecording()¶
Stops the current microphone recording
pulse_audio_recorder¶
The AudioRecorder class manages the caption of audio from the microphones on the NICO robot using PulseAudio.
- class nicoaudio.pulse_audio_recorder.AudioRecorder(audio_channels, samplerate, datadir, audio_device)¶
Bases:
object- rec_from_mic(n_sec=20, rec_id=0)¶
Record for n seconds and returns frames. :param n_sec: duration of the recording :type n_sec: int :param rec_id: id of the recording :type rec_id: int
- Returns
recorded frames
- Return type
list
- start_recording(label, rec_id=0, fname='test.wav', dir_name='./data_shake/')¶
Start threaded recording
- Parameters
label (str) – name of the recording
rec_id (int) – id of the recording
fname (str) – name of the file
dir_name (str) – name of the directory
- stop_recording(rec_id)¶
Stop recording with given id
- Parameters
rec_id (int) – id of the recording
- nicoaudio.pulse_audio_recorder.ensure_dir(directory)¶
Creates directory if it doesn’t exist, as well as missing intermediate ones.
- Parameters
directory (str) – path of the directory
- nicoaudio.pulse_audio_recorder.get_pulse_device()¶
Detects pulse device
- Returns
id of the pulse device
- Return type
int
- nicoaudio.pulse_audio_recorder.threaded(f, daemon=False)¶
function decorator
TextToSpeech¶
The TextToSpeech class allows simple speech generation and manipulation using either gTTS, pico2wave or MozillaTTS.
- class nicoaudio.TextToSpeech.TextToSpeech(cache_dir='/tmp', port='http://0.0.0.0:5002/api/tts')¶
Bases:
objectTextToSpeech is a simple text to speech module for different languages
- say(text, language='en-GB', pitch=0, speed=1.0, blocking=True)¶
Generates and plays spoken text using gTTS if google is available or pico2wave as fallback if there is no cached file available.
- Parameters
text (str) – text to speak
language (str) – Language code (e.g. ‘en-GB’ or ‘de’)
pitch (float) – Pitch in octaves by which to shift the output (this affects the speed)
speed (float) – Percentage to increase/decrease speed without changing pitch
blocking (bool) – whether this call should block during playback
- Returns
Playback duration left (0 if blocking)
- Return type
float