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

Need help talk back audio #2

Open
motoleon opened this issue May 17, 2021 · 3 comments
Open

Need help talk back audio #2

motoleon opened this issue May 17, 2021 · 3 comments

Comments

@motoleon
Copy link

Hi. First many thanks.
I need help sending audio to web cam.
I dont how to do it, i need an example code (python) to send audiio to web cam, please.

Many thanks for your great job!

@janglapuk
Copy link
Owner

if __name__ == '__main__':

    cam = XMCam(CAM_IP, CAM_PORT, 'admin', 'admin')
    login = cam.cmd_login()
    print(login)

    sleep(0.1)

    streamconn = cam.create_sub_connection(True)

    sleep(0.1)
    
    success, pcm_audio_path = XMCam.talk_convert_to_pcm('/path/to/audio/file.mp3')

    if success: # if audio converted into PCM successfully

        streamconn.cmd_talk_claim()
        
        sleep(0.1)

        cam.cmd_talk_start()
        
        audio_chunks = XMCam.talk_get_chunks(pcm_audio_path)

        if audio_chunks is not None:

            for audio_chunk in audio_chunks:
                streamconn.cmd_talk_send_stream(audio_chunk)
                sleep(0.04)

            sleep(0.1)

        cam.cmd_talk_stop()
        
        sleep(0.1)

    streamconn.disconnect()
    
    sleep(0.1)

    cam.disconnect()

Just improve the sleep position and time to improve prefered continous audio stream.

Hope this help.

@janglapuk
Copy link
Owner

Just forget/remove streamconn.disconnect() line, because subconnection should not be a keepalive connection. It's should be disconnected automatically after requested keepalive timed out.

@motoleon
Copy link
Author

"xcam Cannot start keepalive" error

dont connect, user admin and password ***** are corrects.
python 2.7 and 3.9 testing

from xmcam import *
from xmconst import *
from time import sleep

CAM_IP = '192.168.0.4'
CAM_PORT = 34567

if name == 'main':
xm = XMCam(CAM_IP, CAM_PORT, 'admin', 'xxxxxxxx')
login = xm.cmd_login()

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

2 participants