Chapter 2: Audio
Import Audio
Multi-Step Process for Uploading and Processing Audio Files
-
After the upload, the mutation named
importAudio
imports audio into the system for further processing. -
With this mutation, the document element is created in the backend. The
uniqueObjName
parameter from thegetPresignedAwsUrl
query is crucial here. It’s required to save the results for the corresponding element.
Input Parameters
-
date
(Date!
)
The date associated with the audio file, typically representing when it was recorded. -
name
(String!
)
The name or title of the audio file. -
language
(String!
)
The language code of the audio content. Supported options include:'de-DE'
(German - Germany)'de-CH'
(German - Switzerland)'de-AT'
(German - Austria)'en-EN'
(English)
-
uniqObjName
(String!
)
The object name used to locate the audio file, often corresponding to the S3 key or filename. this key needs to be unique, you can use our recommended random number generator to create this object, it should be 30 charactersfunction generateRandomId(length) { let id = ""; const charset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; const charsetLength = charset.length; for (let i = 0; i < length; i++) { const randomIndex = Math.floor(Math.random() * charsetLength); id += charset.charAt(randomIndex); } return id; }
-
duration
(String!
)
The total duration of the audio file, typically in aHH:MM:SS
format. -
typeOfDocument
(String!
)
The type of document to generate from the audio. Supported types include:summary
politics
-
topList
(String!
)
A JSON-stringified array of objects representing the agenda for the audio. This is usually prepared in an external system.- Each object in the array corresponds to an agenda item.
- The structure must conform to the
TopListType
definition. - The
system_id
field within each object is used during the export process back to the parent system.
Ensure all fields are correctly formatted and valid before calling the mutation.
Example GraphQL Mutation (importAudio
):
const IMPORT_AUDIO = `
fragment protocolDetails on ApiProtocolType {
slug
name
status
editStage
date
bucketAws
}
mutation ImportAudio(
$date: Date!
$projectSlug: String!
$name: String!
$language: String!
$uniqueObjName: String!
$duration: String!
$typeOfDocument: String!
$topList: String!
){
importAudio(
name: $name,
projectSlug: $projectSlug,
date: $date,
language: $language,
duration: $duration,
typeOfDocument: $typeOfDocument,
topList: $topList,
uniqueObjName: $uniqueObjName
){
success
protocol{
...protocolDetails
}
}
}
`;
Example Data Object for IMPORT_AUDIO
Mutation
{
query: IMPORT_AUDIO,
variables: {
duration: "150", // in seconds
uniqueObjName: "SNbtVr4Ls7Yzf3jMxX33Yzf3jMxX33",
name: 'Testmeeting', // max 200 chars
date: '01.01.2025',
language: 'de-DE',
typeOfDocument: 'politics', // 'summary' or 'politics'
topList: JSON.stringify([
{
title: 'Agendapoint 1',
systemId: '1' // optional parameter
},
{
title: 'Agendapoint 2',
systemId: '2' // optional parameter
},
])
},
};
Example JS code
import axios from "axios";
async function createAudioBackend(audioItem, uniqueObjName) {
let dataObj = {
query: IMPORT_AUDIO,
variables: {
duration: audioItem.duration, // in seconds
uniqueObjName: uniqueObjName,
name: audioItem.name, // max 200 chars
date: audioItem.date,
language: audioItem.language,
typeOfDocument: audioItem.typeOfDocument, // 'summary' or 'politics'
topList: audioItem.topList
},
};
await axios({
method: "post",
url: process.env.VUE_APP_GRAPHQL_API,
data: JSON.stringify(dataObj),
headers: {
"Content-Type": "application/json",
"x-api-key": process.env.VUE_APP_API_KEY,
},
})
.then(() => {
console.log("Audio created successfully");
})
.catch((error) => {
console.log(error);
})
.finally(() => {
console.log("Upload completed");
});
}
Each step builds upon the previous one:
- The URL from
getPresignedUrl
is utilized for uploading the file to S3, - And the result is then passed to the
importAudio
mutation to complete the process.
Have questions?
Still have questions? Talk to support.