deepgram / deepgram-sdk-architecture

Pseudo-code and comments to support the building of our SDKs
1 stars 0 forks source link

RFC: Remove MIME type for batch in SDKs #4

Open lukeocodes opened 1 year ago

lukeocodes commented 1 year ago

Our ASR API never requires a MIME type unless you are making a fetch request with a JSON body, in which case it must be application/json.

The proposal is to remove this requirement from file requests, which will simplify the SDKs. We unfurl the body from an object, right now. We can just allow the user to pass audio data directly to the prerecorded file methods, and have it turned directly into a body for the POST request.

Existing use:

const result = deepgram.listen.prerecorded.transcribeFile({ buffer: audioBuffer, mimetype: "audio/mp4"}, options); 

Existing SDK code:

  async transcribeFile(
    source: FileSource,
    options?: PrerecordedOptions,
    endpoint = "v1/listen"
  ): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
      if (source.mimetype === undefined || source.mimetype.length === 0) {
        throw new DeepgramError(
          "Mimetype must be provided if the source is a Buffer or a Readable"
        );
      }

      this.headers["Content-Type"] = source.mimetype;

      let body;
      if (isBufferSource(source)) {
        body = source.buffer;
      } else if (isReadStreamSource(source)) {
        body = source.stream;
      } else {
        throw new DeepgramError("Unknown transcription source type");
      }

      // ...

      return await this.post(this.fetch as Fetch, url, body, {
        headers: this.headers,
      });
  }

Proposed use:

const result = deepgram.listen.prerecorded.transcribeFile(audioBuffer, options); 

Proposed SDK code:

  async transcribeFile(
    source: Buffer,
    options?: PrerecordedOptions,
    endpoint = "v1/listen"
  ): Promise<DeepgramResponse<SyncPrerecordedResponse>> {
      // ...

      return await this.post(this.fetch as Fetch, url, source, {
        headers: this.headers,
      });
  }
lukeocodes commented 1 year ago

Moving to open as it was discussed in Slack prior to raising as an RFC.