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

real time. with out wait whole reply done, button actually appear. #46

Open
happyf-weallareeuropean opened this issue Dec 23, 2024 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@happyf-weallareeuropean

what is this challenge of this feature?

@adamlui
Copy link
Owner

adamlui commented Dec 23, 2024

@happyf-weallareeuropean currently the script just relies on the button (front-end method) so for your feature requires back-end method + API allows speak before completion but I never worked w/ this method before but I can look into it

@adamlui adamlui added enhancement New feature or request help wanted Extra attention is needed labels Dec 23, 2024
@adamlui
Copy link
Owner

adamlui commented Dec 23, 2024

I just played with the API for awhile and it was too hardcore to implement from IDK what to do w/ the response. But this is where I got (xhr() is wrapper for userscript manager's XHR method, also requires chatgpt.js to get token):

    function speak() {
        const synthEndpoint = 'https://chatgpt.com/backend-api/synthesize'
        const msgID = '7fd31ce3-c6cc-4820-8166-4aed9f49f301'
        const convoID = '67695cab-a0f0-800f-b79f-481c030a9f87'
        const voice = 'cove'
        chatgpt.getAccessToken().then(token => {
            xhr({
                method: 'GET', url: `${synthEndpoint}?message_id=${msgID}&conversation_id=${convoID}&voice=${voice}`,
                headers: {
                    'Accept': '*/*', 'Accept-Encoding': 'gzip, deflate, br, zstd',
                    'Authorization': `Bearer ${token}`,
                    'Connection': 'keep-alive', 'DNT': '1',
                    'Host': 'chatgpt.com',
                    'OAI-Device-Id': 'b6e61267-b02e-42dc-837b-9e0d852af0e3', 'OAI-Language': 'en-US',
                    'Priority': 'u=4', 'Referer': 'https://chatgpt.com/c/67695cab-a0f0-800f-b79f-481c030a9f87',
                    'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-origin'
                },
                onload: resp => {
                    if (resp.status != 200) {
                        console.error('Response status', resp.status)
                        return console.info(resp)
                    }
                    console.log('Audio content received', resp)
                    const audioBlob = new Blob([resp.response], { type: 'audio/aac' }),
                          audioURL = URL.createObjectURL(audioBlob),
                          audio = new Audio(audioURL)
                    audio.play().then(() => console.log('Audio is playing'))
                        .catch(err => console.error('Error playing audio', err))
                }
            })
        })
    }

The msgID + convoID + voice + OAI-Device-Id + OAI-Language should be replaced with actual user values if anyone can get it to play (probably requires converting response data to AAC file) then I can make it dynamic for this script

@adamlui
Copy link
Owner

adamlui commented Dec 23, 2024

Actually upon reflection, I think the msg ID isn't generated until response completion but even if before, I think the msg thus audio file will not contain all the words yet so your feature is not possible

@happyf-weallareeuropean
Copy link
Author

thank your respond adamlui! i was though use siri.
i not sure in rule of select / muti request to unreal real time. i well started try this tonight, share with you update later!

@adamlui
Copy link
Owner

adamlui commented Jan 1, 2025

@happyf-weallareeuropean are you really good at JS/APIs though? Because advanced knowledge is required to play with the code I pasted

@happyf-weallareeuropean
Copy link
Author

happyf-weallareeuropean commented Jan 1, 2025

nah, just start it swift 3 mo. from playgrounds switch to xcode as 2 week earlyer

@happyf-weallareeuropean
Copy link
Author

i will take care, any stock share with u also!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants