Edits history of script submission #20975 for ' Create audio generation request (togetherai)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Togetherai = {
      api_key: string;
    };
    /**
     * Create audio generation request
     * Generate audio from input text
     */
    export async function main(
      auth: Togetherai,
      body: {
        model: string;
        input: string;
        voice: string;
        response_format?: "mp3" | "wav" | "raw";
        language?:
          | "en"
          | "de"
          | "fr"
          | "es"
          | "hi"
          | "it"
          | "ja"
          | "ko"
          | "nl"
          | "pl"
          | "pt"
          | "ru"
          | "sv"
          | "tr"
          | "zh";
        response_encoding?: "pcm_f32le" | "pcm_s16le" | "pcm_mulaw" | "pcm_alaw";
        sample_rate?: number;
        stream?: false | true;
      },
    ) {
      const url = new URL(`https://api.together.xyz/v1/audio/speech`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.api_key,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 235 days ago