Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[idea] AI voice narration #289

Open
louis030195 opened this issue Dec 21, 2024 · 1 comment
Open

[idea] AI voice narration #289

louis030195 opened this issue Dec 21, 2024 · 1 comment

Comments

@louis030195
Copy link

louis030195 commented Dec 21, 2024

i use this templater shortcut to generate voice out of selected note:

const fs = require('fs');

function generateUUID() {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
        var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
        return v.toString(16);
    });
}

const audio = async (conf, dir) => {
    const openAIKey = conf.openai;
    
    document.body.style.cursor = "wait";
    const selection = window.getSelection().toString();
    const url = "https://api.openai.com/v1/audio/speech";
    
    const response = await fetch(url, {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
            "Authorization": `Bearer ${openAIKey}`
        },
        body: JSON.stringify({
            model: "tts-1",
            voice: "onyx",
            input: selection,
            response_format: "mp3"
        })
    });

    if (!response.ok) {
        const text = await response.text();
        throw new Error(`HTTP error! status: ${response.status} ${text}`);
    }

    const audioBuffer = await response.arrayBuffer();
    const audioTitle = generateUUID();
    const folder = dir.replace(/[^/]+$/, '');

    await app.vault.adapter.writeBinary(
        `${folder}/${audioTitle}.mp3`, 
        audioBuffer
    );

    document.body.style.cursor = "default";

    return `![[${audioTitle}.mp3]]`;
}

module.exports = audio;

maybe could be something in fo2k, when moving to inbox, probably you'd have to use prompt to only read the relevant part (and ignore tags and markdown stuff like this)

i like to have a read option (esp when using obsidian publish)

i think substack and stuff like this do it too

Copy link

linear bot commented Dec 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant