Class AIDictationServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class AIDictationServlet
    extends org.apache.sling.api.servlets.SlingAllMethodsServlet
    Servlet providing a dictation service - returns a transcribed text from an audio file.
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void activate​(org.osgi.framework.BundleContext bundleContext)  
      protected void doGet​(@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 void doPost​(@NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
      Implements the transcription operation.
      protected String getMandatoryParameter​(org.apache.sling.api.SlingHttpServletRequest request, org.apache.sling.api.SlingHttpServletResponse response, String parameterName)  
      protected Integer getOptionalInt​(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
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletName, init, init, log, log
    • 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
      • bundleContext

        protected org.osgi.framework.BundleContext bundleContext
    • Constructor Detail

      • AIDictationServlet

        public AIDictationServlet()
    • 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,
                             IOException
        Returns whether dictation is enabled for the content in the suffix: status code OK means it's available, otherwise 404.
        Overrides:
        doGet in class org.apache.sling.api.servlets.SlingSafeMethodsServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doPost

        protected void doPost​(@NotNull
                              @NotNull org.apache.sling.api.SlingHttpServletRequest request,
                              @NotNull
                              @NotNull org.apache.sling.api.SlingHttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
        Implements 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
        If there is a sling suffix in the URL, we'll use it to determine the configuration. A successful response will return an HTTP 200 with the text as text/plain, UTF-8. Otherwise, it'll normally be an HTTP 400 with an error message.
        Overrides:
        doPost in class org.apache.sling.api.servlets.SlingAllMethodsServlet
        Throws:
        javax.servlet.ServletException
        IOException