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

What is the internal method to play audio in hfp_hf? (IDFGH-13872) #14718

Open
Stewart-Anubis opened this issue Oct 13, 2024 · 1 comment
Open
Assignees
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF

Comments

@Stewart-Anubis
Copy link

Is your feature request related to a problem?

No response

Describe the solution you'd like.

Hello,

I am trying to create something similar to a Bluetooth answering machine using hfp_hf. The main function would be to automatically answer calls from my Android phone and play a greeting message stored in a WAV file on the SD card connected to the ESP32. The message will be played to the caller as if someone is speaking into the microphone, and immediately after playing the message, the call will be terminated.

I have already managed to automatically answer the call and initialize the SD card in the ESP32 code, but I have not found a method to play the 'greeting.wav' file for the caller.

Since the project is only about automatically answering, playing the greeting, and hanging up the call, I am trying to keep it as simple as possible by only using the ESP32 and an SD card module.

Is there a method I can use to play 'greeting.wav' within the ESP32 with hfp_hf so that the caller can hear it right after the code answers the call, without using any external peripherals?

Describe alternatives you've considered.

No response

Additional context.

No response

@Stewart-Anubis Stewart-Anubis added the Type: Feature Request Feature request for IDF label Oct 13, 2024
@espressif-bot espressif-bot added the Status: Opened Issue is new label Oct 13, 2024
@github-actions github-actions bot changed the title What is the internal method to play audio in hfp_hf? What is the internal method to play audio in hfp_hf? (IDFGH-13872) Oct 13, 2024
@BetterJincheng
Copy link
Collaborator

@Stewart-Anubis

/**
* @brief           HFP client outgoing data callback function, the callback is useful in case of
*                  Voice Over HCI. Once audio connection is set up and the application layer has
*                  prepared data to send, the lower layer will call this function to read data
*                  and then send. This callback is supposed to be implemented as non-blocking,
*                  and if data is not enough, return value 0 is supposed.
*
* @param[in]       buf : pointer to incoming data(payload of HCI synchronous data packet), the
*                  buffer is allocated inside bluetooth protocol stack and will be released after
*                  invoke of the callback is finished.
*
* @param[in]       len : size(in bytes) in buf
*
* @return          length of data successfully read
*
*/
typedef uint32_t (* esp_hf_client_outgoing_data_cb_t)(uint8_t *buf, uint32_t len);

To play 'greeting.wav' within the ESP32,you can save the .wav into SD card and load len bytes in every callback for outgoing data.

It should be noted that the operations in the callback should be as fast as possible. So, reading data from the SD card in callback is not a good choice. One possible approach is to use an backgroud task to transfer data from the SD card to the ringbuffer, and directly retrieve the data from the ringbuffer in the callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Opened Issue is new Type: Feature Request Feature request for IDF
Projects
None yet
Development

No branches or pull requests

3 participants