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

Support for speakers as media_player entity in HA #126

Open
WhistleMaster opened this issue Apr 2, 2022 · 12 comments
Open

Support for speakers as media_player entity in HA #126

WhistleMaster opened this issue Apr 2, 2022 · 12 comments

Comments

@WhistleMaster
Copy link

Hi,

Thanks for the great work !

I've recently installed a new AXIS I8016-LVE and I was wondering if the internal speaker could be seen in HA as a media_player entity. The Synology surveillance client can send any sound file to the speaker, so there may be a way I guess. Then, that could also be applied to other AXIS Network Speakers such as the C1410.

What information would you need that could help ?

Thanks !
Kind regards,

WM

@Kane610
Copy link
Owner

Kane610 commented Apr 2, 2022

It's on my list to investigate. I'm rewriting deconz integration right now. Then I'll solve some bugs with unifi then I hope to get back to the Axis integration

@WhistleMaster
Copy link
Author

Great news ! I would be happy to test and provide information if needed.

@Kane610
Copy link
Owner

Kane610 commented Apr 2, 2022

Don't expect it to happen before summer though :/

I have too much to do which is the main issue

@WhistleMaster
Copy link
Author

Summer is the best time to test ;-) No worries !

@WhistleMaster
Copy link
Author

I'm doing some tests in the meanwhile and I can send sample sounds to the internal speaker with the following command:

ffmpeg -i <sound_file.mp3> -probesize 32 -analyzeduration 32 -c:a pcm_mulaw -ab 128k -ac 1 -ar 16000 -f wav -chunked_post 0 -content_type audio/axis-mulaw-128 "http://<user>:<password>@<cam_ip>/axis-cgi/audio/transmit.cgi"

@Kane610
Copy link
Owner

Kane610 commented Nov 22, 2022

Oo wow! Awesome job.

@WhistleMaster
Copy link
Author

Thanks ! Just some good old google-fu to be honest 😇 nothing more.
I would like to help to implement that in your add-on but not sure if that really helps... It's a start but I guess that's something that should use some POST to send the sound file to the transmit.cgi and see it as a media_player entity.

@Kane610
Copy link
Owner

Kane610 commented Nov 22, 2022

If you can just give me a proof of concept in python code I can formalize it afterwards

@WhistleMaster
Copy link
Author

I've tried to do something like that, as a PoC, which works fine:

import requests
from requests.auth import HTTPDigestAuth
from pydub import AudioSegment
from pydub.utils import mediainfo

# Set Auth
auth = HTTPDigestAuth("<USER>", "<PASSWORD>")

# Set the server URL
server_url = "http://<IP>/axis-cgi/audio/transmit.cgi"

# Open the MP3 file
input_file = AudioSegment.from_mp3("sound.mp3")

# Convert the MP3 file to WAV format
input_file = input_file.split_to_mono()[0]
input_file = input_file.set_frame_rate(16000)
input_file = input_file.export(
    "output.wav", format="wav", codec="pcm_mulaw", bitrate="128k")

# Print some info about the WAV
print(mediainfo("output.wav"))

# Read the WAV file and get its data
with open("output.wav", "rb") as f:
    file_data = f.read()

# Set the headers for the HTTP POST request
headers = {
    "Content-Type": "audio/axis-mulaw-128",
    "Content-Length": str(len(file_data)),
}

try:
    # Send the POST request with the file data and headers
    response = requests.post(server_url, data=file_data,
                             auth=auth, headers=headers)
    print(response.text)
    response.raise_for_status()
except requests.exceptions.HTTPError as errh:
    print("Http Error:", errh)
except requests.exceptions.ConnectionError as errc:
    print("Error Connecting:", errc)
except requests.exceptions.Timeout as errt:
    print("Timeout Error:", errt)
except requests.exceptions.RequestException as err:
    print("OOps: Something Else", err)

I've also found some documentation here: https://www.axis.com/vapix-library/subjects/t10100065/section/t10036015/display

@Kane610
Copy link
Owner

Kane610 commented Jan 2, 2023

Sweet! I've taken my first small steps into the refactoring of the Axis library so once I'm further into that I can start looking at adding new things as it would be counterproductive to expand something that will be rewritten shortly after.

@jonoberheide
Copy link

FYI, I posted a PR for speaker support in HA here: home-assistant/core#130163

@Kane610
Copy link
Owner

Kane610 commented Nov 9, 2024

Awesome 🎉

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

3 participants