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

Two-way audio working? #762

Closed
borgqueenx opened this issue Nov 27, 2023 · 18 comments
Closed

Two-way audio working? #762

borgqueenx opened this issue Nov 27, 2023 · 18 comments
Labels

Comments

@borgqueenx
Copy link

Hey there yi hacks! I bought 5 dome u pro cameras tbis black friday and wondering if we could use two-way audio on the device. I found two discussions regarding this that say we can use a text to speech service and upload a wav file, but nothing about using a microphone to talk live while watching the (rtsp?) Stream.
Is this now possible or has it been found unfortunately not possible?
Thanks!

@roleoroleo
Copy link
Owner

If you enable sound in the web gui, the rtsp will contain an audio channel.
You can get an audio only stream using the url rtsp://IP-CAM/ch0_2.h264

About the speaker, at the moment you can use it in two ways:

Check the wiki for the syntax:
https://github.com/roleoroleo/yi-hack-Allwinner-v2/wiki/Web-services-description#audio

These features are integrated in the ha custom component and you can use them from ha as a service.

@roleoroleo
Copy link
Owner

Another use, there is a hidden web page:
http://IP-CAM/?page=speak

@borgqueenx
Copy link
Author

borgqueenx commented Nov 29, 2023 via email

@AlexxIT
Copy link

AlexxIT commented Nov 30, 2023

Dahua cameras support multipart POST for playing audio files
AlexxIT/go2rtc#52 (comment)

I can try to support something like this. Multipart uses for sending multiple audio chunks to single POST connection.

@roleoroleo
Copy link
Owner

roleoroleo commented Dec 1, 2023

Please, explain me better.

EDIT

Actually the speaker.sh cgi handles a multipart post of this type:
immagine
immagine
Where the content is a raw file S16LE / 16 KHz, 16 bit, mono (or a wav file with the same parameters).

@AlexxIT
Copy link

AlexxIT commented Dec 1, 2023

Does it support multiple multipart files in same connection? One by one with little delay between.

@roleoroleo
Copy link
Owner

No, at the moment.

@roleoroleo
Copy link
Owner

Maybe I could implement it server side (within the cam).
But is there a JavaScript example to send multipart/x-mixed-replace data?
I found many examples on how to receive streaming from a server but nothing to upload.

@AlexxIT
Copy link

AlexxIT commented Dec 3, 2023

I don't know of any such examples.
And haven't implemented anything similar for sending data yet. I've only done it for receiving data.

@Dotatay
Copy link

Dotatay commented Dec 15, 2023

The idea is so cool. I’m not good at JavaScript, but I tried to get an example from Codex:

const audioFile = new File(["audio.raw"], "audio.raw");
const buffer = await audioFile.readAsArrayBuffer();
fetch("https://example.com/upload", {
  method: "POST",
  headers: {
    "Content-Type": "audio/x-raw, format=S16LE, rate=16000, channels=1"
  },
  body: [
    {
      name: "audio",
      data: new Uint8Array(buffer)
    }
  ]
});

Second example:

let formData = new FormData();
formData.append("audio", new Blob([new Uint8Array(buffer)], {type: "audio/x-raw, format=S16LE, rate=16000, channels=1"}));

fetch("https://example.com/upload", {
  method: "POST",
  body: formData
})
.then(response => response.json())
.then(result => console.log(result))
.catch(error => console.log('error', error));

@kyutov
Copy link

kyutov commented Feb 16, 2024

@roleoroleo - is it possible to stream audio through the speaker of the camera? I have two h60ga cameras. I'm trying to achieve this Smart Baby Monitor. In short what I want to achieve it to capture the sound through ffmpeg_noise sensor in home assistant from the RTSP audio stream of the first camera, to upload it to Icecast 2 server and then to stream it through the speaker of the second camera when home assistant detects baby cry in the RTSP audio stream.
If it is not possible at the moment to stream audio through the speaker of the camera, will it possible to add such functionality to the hack?

@roleoroleo
Copy link
Owner

You can send an audio file to the cam but a stream is not supported.
About capture, you can use the rtsp stream, there is an only audio stream.

@kyutov
Copy link

kyutov commented Feb 16, 2024

Yes, I have already managed to capture the audio through the audio stream of the camera. Unfortunately the output creates audio file, which is continually feeded from the audio stream so there is no way to have a completed file which can be sent to the camera.
According to you will it be possible to add streaming functionality to the hack?

@roleoroleo
Copy link
Owner

Take a look to this repo:
https://github.com/roleoroleo/yi-hack_rtp_streamer

@kyutov
Copy link

kyutov commented Feb 26, 2024

Wow, this is great! Thank you!

I have tried both streaming ways (streamer/received and streaming using ffmpeg) and both of them are working. While using streamer/received I cannot control the volume and it is too low, but when I stream using ffmpeg I can control it so I got really good result.

I need to find out a way to start and stop the streamer and the receiver from Home Assistant. Will it be hard to add such functionality?

@roleoroleo
Copy link
Owner

You could create a ha script to run a remote command through ssh.

@kyutov
Copy link

kyutov commented Feb 28, 2024

Yes, I will go in this direction. Thanks for the suggestion and for the rtp streamer which you have created 👍

Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale label May 29, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants