Media - How to save and work with microphone recordings

The microphone control offers a useful and valuable feature. However, it isn't clear from the documentation how to save or to access recordings from a data source. In this post, we'll walk through how to store and retrieve audio files in a Dataverse database.

Introducing the microphone control

To make recordings, we add a microphone control using the Insert > Media menu item. At runtime, this control displays a button with a microphone icon. The user can click the button to start a recording, and a timer inside the button will show the elapsed time. The user can click the button again to stop the recording.

In formula, we can access the recording through the Audio property.

To illustrate the most basic usage, we can add an audio control to a screen and configure it to play the microphone recording by setting the Media property to Microphone1.Audio (where Microphone1 refers to the microphone control).

Saving microphone recordings

Although we can easily access the recording that a user makes, it isn't obvious how to save this recording. The data source with the best support for storing audio files is Dataverse. This is because it offers the option to define columns of data type 'file'.

If we choose a different data source such as SharePoint, we can use the JSON function to Base64 encode the audio data, and to store this in a text field. We can reuse the same technique that app builders regularly use to store camera images in SharePoint.

To save our recordings to Dataverse. The first step is to create a table. In this example, we'll name our table AudioRecordings, and we'll add a file column called AudioData.


Patching audio (or file content) to a Dataverse table

From our app, we can add a connection to the table. From our screen, we can add a microphone control and a button that patches the audio content as a new record in the table. This is the formula that we would add to the OnSelect property of the button.

Patch(AudioRecordings, 
Defaults(AudioRecordings),
{Name:"Record title for row in Dataverse table" ,
AudioData:{FileName:"Filename.wav",
Value:Microphone1.Audio
}
}
)

This formula provides a good illustration of how to patch binary files to a file column in Dataverse. At the time of writing, it isn't obvious how to do this because the IntelliSense does not show the expected properties for the file field.

To specify a file, we pass a record and there are two properties that we need to specify - the file name (FileName) , and the binary content (Value). In this example, we specify the file name "Filename.wav" but in practice, we can create a file name based on the current date and time. We reference the Audio property of the microphone control to specify the microphone recording.

At this point, we can run our app, make a recording, and click the button to save the recording.

Displaying and playing audio files

To provide a method for users to play back recordings, we can add a gallery control and set the Items property to the AudioRecordings table.

From the gallery control, we can display the file name by using the syntax: ThisItem.AudioData.FileName

We can then add an audio control, and we can configure this to play the file that the user selects in the gallery control by setting the Media property to:

Gallery1.Selected.AudioData.Value

Conclusion

A great feature in canvas apps is the ability to make recordings using microphone control. This post walked through how to use this control, including how to create a table in Dataverse to store the audio content, how to patch a recording as a new record, and how to access saved recordings.

Related posts

Dataverse - How to set yes no values with checkbox- Walkthrough
January 29, 2025
Dataverse - Add image column missing when creating table - how to fix
January 19, 2025
Data - How to view the progress and status of a Dataverse CSV/Excel Import
January 15, 2025
Error - Diagnosing the error "Network error when using the Patch function" when saving data with a form
May 05, 2024
Dataverse - How to work around the error "multiple levels of many-to-one relationship expansion aren't supported"
April 05, 2024
Dataverse - The easiest way to modify Dataverse data outside of Dataverse and Power Apps
February 18, 2024
Dataverse - How to use a checkbox control a set a yes/no field in Dataverse
July 10, 2023
Dataverse - How to create Entity Relationship diagrams
January 22, 2023
Dataverse - How you can more quickly bulk update data using the SQL language
January 14, 2023
Dataverse - How to fix the bug in the 'Business Rules' editor that prevents numeric values from saving
January 05, 2023
Dataverse - What are the benefits, and how to create formula columns
July 20, 2022
Dataverse - How to sort the available choice items from a choice column
May 12, 2022
Error - Unable to modify Dataverse tables with error message, Language id should not be null
September 27, 2021
Dataverse - How to retrieve FetchXML or SQL for Dataverse views
July 13, 2021
Data - Why is Dataverse so fast?
June 15, 2021
Dataverse - How to create and use Dataverse views in Canvas Apps
June 09, 2021
Dataverse - How to filter Dataverse choice columns
June 07, 2021
Dataverse - How to switch to the classic designer when the option is not available
May 26, 2021
Licensing - What are Dataverse Restricted tables?
March 26, 2021
Dataverse - how to access tables from another environment
February 23, 2021
Dataverse - How to Patch the 5 most complex data types
January 19, 2021