# The τ Recorder API

## `openAudioSession()` and `closeAudioSession()`

* Dart API: [openAudioSession](https://github.com/Canardoux/tau/tree/6bd245d293bcf9a123677735835549585d32b2ee/doc/pages/tau-api/recorder/pages/flutter-sound/api/recorder/FlutterSoundRecorder/openAudioSession.html)
* Dart API: [closeAudioSession](https://github.com/Canardoux/tau/tree/6bd245d293bcf9a123677735835549585d32b2ee/doc/pages/tau-api/recorder/pages/flutter-sound/api/recorder/FlutterSoundRecorder/closeAudioSession.html)

A recorder must be opened before used. A recorder correspond to an Audio Session. With other words, you must *open* the Audio Session before using it. When you have finished with a Recorder, you must close it. With other words, you must close your Audio Session. Opening a recorder takes resources inside the OS. Those resources are freed with the verb `closeAudioSession()`.

You MUST ensure that the recorder has been closed when your widget is detached from the UI. Overload your widget's `dispose()` method to close the recorder when your widget is disposed. In this way you will reset the player and clean up the device resources, but the recorder will be no longer usable.

```dart
@override
void dispose()
{
        if (myRecorder != null)
        {
            myRecorder.closeAudioSession();
            myPlayer = null;
        }
        super.dispose();
}
```

You maynot openAudioSession many recorders without releasing them. You will be very bad if you try something like :

```dart
    while (aCondition)  // *DO'NT DO THAT*
    {
            flutterSound = FlutterSoundRecorder().openAudioSession(); // A **new** Flutter Sound instance is created and opened
            ...
    }
```

`openAudioSession()` and `closeAudioSession()` return Futures. You may not use your Recorder before the end of the initialization. So probably you will `await` the result of `openAudioSession()`. This result is the Recorder itself, so that you can collapse instanciation and initialization together with `myRecorder = await FlutterSoundPlayer().openAudioSession();`

The four optional parameters are used if you want to control the Audio Focus. Please look to [FlutterSoundPlayer openAudioSession()](https://github.com/Canardoux/tau/tree/6bd245d293bcf9a123677735835549585d32b2ee/doc/pages/tau-api/recorder/player.md#openaudiosession-and-closeaudiosession) to understand the meaning of those parameters

*Example:*

[Dart](/tau/doc/pages/tau-api/recorder/open_audio_session.md#dart)

[Javascript](/tau/doc/pages/tau-api/recorder/open_audio_session.md#javascript)

```

    myRecorder = await FlutterSoundRecorder().openAudioSession();

    ...
    (do something with myRecorder)
    ...

    myRecorder.closeAudioSession();
    myRecorder = null;
```

```

        Lorem ipsum ...
```

\</div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://canardoux.gitbook.io/tau/doc/pages/tau-api/recorder/open_audio_session.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
