Class AIDictationServlet
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- org.apache.sling.api.servlets.SlingSafeMethodsServlet
-
- org.apache.sling.api.servlets.SlingAllMethodsServlet
-
- com.composum.ai.backend.slingbase.AIDictationServlet
-
- All Implemented Interfaces:
Serializable,javax.servlet.Servlet,javax.servlet.ServletConfig
public class AIDictationServlet extends org.apache.sling.api.servlets.SlingAllMethodsServletServlet providing a dictation service - returns a transcribed text from an audio file.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected org.osgi.framework.BundleContextbundleContextprotected AIConfigurationServiceconfigurationServiceprotected com.composum.ai.backend.base.service.chat.GPTDictationServicedictationServicestatic StringPARAMETER_AUDIO_STREAMParameter to transmit the audio stream to be transcribed.static StringPARAMETER_CONTENT_TYPEParameter to transmit the content type of the audio, e.g.static StringPARAMETER_LANGUAGEParameter to transmit the language code to use, e.g.static StringPARAMETER_PROMPTParameter to transmit an optional prompt to give the AI some context, e.g.
-
Constructor Summary
Constructors Constructor Description AIDictationServlet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidactivate(org.osgi.framework.BundleContext bundleContext)protected voiddoGet(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)Returns whether dictation is enabled for the content in the suffix: status code OK means it's available, otherwise 404.protected voiddoPost(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)Implements the transcription operation.protected StringgetMandatoryParameter(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, String parameterName)protected IntegergetOptionalInt(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, String parameterName)-
Methods inherited from class org.apache.sling.api.servlets.SlingAllMethodsServlet
doDelete, doPut, getAllowedRequestMethods, isMethodValid, mayService
-
Methods inherited from class org.apache.sling.api.servlets.SlingSafeMethodsServlet
doGeneric, doHead, doOptions, doTrace, getServletInfo, handleMethodNotImplemented, service, service
-
-
-
-
Field Detail
-
PARAMETER_AUDIO_STREAM
public static final String PARAMETER_AUDIO_STREAM
Parameter to transmit the audio stream to be transcribed.- See Also:
- Constant Field Values
-
PARAMETER_CONTENT_TYPE
public static final String PARAMETER_CONTENT_TYPE
Parameter to transmit the content type of the audio, e.g. "audio/mpeg" for mp3, "audio/wav" for wav.- See Also:
- Constant Field Values
-
PARAMETER_LANGUAGE
public static final String PARAMETER_LANGUAGE
Parameter to transmit the language code to use, e.g. "en" for English, or null for automatic detection.- See Also:
- Constant Field Values
-
PARAMETER_PROMPT
public static final String PARAMETER_PROMPT
Parameter to transmit an optional prompt to give the AI some context, e.g. previous sentences.- See Also:
- Constant Field Values
-
configurationService
protected AIConfigurationService configurationService
-
dictationService
protected com.composum.ai.backend.base.service.chat.GPTDictationService dictationService
-
bundleContext
protected org.osgi.framework.BundleContext bundleContext
-
-
Method Detail
-
activate
public void activate(org.osgi.framework.BundleContext bundleContext)
-
getOptionalInt
protected Integer getOptionalInt(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, String parameterName) throws IOException
- Throws:
IOException
-
getMandatoryParameter
protected String getMandatoryParameter(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, String parameterName) throws IOException
- Throws:
IOException
-
doGet
protected void doGet(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOExceptionReturns whether dictation is enabled for the content in the suffix: status code OK means it's available, otherwise 404.- Overrides:
doGetin classorg.apache.sling.api.servlets.SlingSafeMethodsServlet- Throws:
javax.servlet.ServletExceptionIOException
-
doPost
protected void doPost(@NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response) throws javax.servlet.ServletException, IOExceptionImplements the transcription operation. Input parameters are (as a multipart form):- file: the audio stream to transcribe
- contentType: the content type of the audio, e.g. "audio/mpeg" for mp3, "audio/wav" for wav
- language: the language code to use, e.g. "en" for English, or null / empty for automatic detection
- prompt: an optional prompt to give the AI some context, e.g. previous sentences
- Overrides:
doPostin classorg.apache.sling.api.servlets.SlingAllMethodsServlet- Throws:
javax.servlet.ServletExceptionIOException
-
-