Skip to content

Develop a voice input feature similar to WeChat #228

@jerryokk

Description

@jerryokk

Clear and concise description of the problem

Create a voice input feature that allows users to record audio by long-pressing a button for up to 60 seconds. Users can cancel the recording by sliding up and releasing the button to send the audio. After sending the audio, the feature will use OpenAI's audio API to convert the audio into text and send it to ChatGPT.

长按录音,最大录音60s,上滑取消,松手发送。发送后通过 openai 的 audio 接口转成文字发送给 chatgpt api。

Suggested solution

const formData = new FormData();
formData.append("file", audioFile);  // WebM 录制的文件
formData.append("model", model);
formData.append("prompt", prompt);   // 提示中写使用简体中文,否则默认出来的是繁体的
formData.append("response_format", "json");
formData.append("temperature", temperature);
formData.append("language", language);

fetch(BASE_URL + "/v1/audio/transcriptions", {
    method: "POST",
    headers: {
        "Authorization": "Bearer " + API_KEY
    },
    body: formData
})
.then(response => {
    if (!response.ok) {
        throw new Error("HTTP error " + response.status);
    }
    return response.json()
})
.then(json => {
    // 转写的文本在 json.text
})
.catch(error => {
    console.error(error);
});

Alternative

No response

Additional context

OpenAI's audio API charges $0.006 per minute for transcription.

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions