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

preliminary audio support #76

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

preliminary audio support #76

wants to merge 5 commits into from

Conversation

ubaldus
Copy link

@ubaldus ubaldus commented Sep 3, 2020

Hello everyone and thank you for the great job done so far! :)

while(--timeout)
{
Trace(1,"recording");
OS_Sleep(1000);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better not to make sleep here. It will block the python main thread and won’t allow any callbacks to run until recording finishes. I would run it in another thread ( task). It’s also applies to the play function

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, play doesn't need the sleep at all indeed and the record timeout could be managed with the data callback from AUDIO_RecordStart.

Should I send a new pull request or should I wait for this to be merged first?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I have renamed audio_record to audio_record_start and audio_play to audio_play_start and removed any sleep so we can manage timeout and any other kind of interaction directly from python.

No idea yet on how to pass the fileFd to AUDIO_Resume() so it is commented out at the moment.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it, and works fine ^^
I changed args to 4 to play mp3 files.
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modaudio_play_start_obj, 1, 4, modaudio_play_start);

import audio
audio.play_start("/t/099-Az-zalzala.mp3",15,2,5) # AUDIO_TYPE_MP3 = 5
audio.play_stop()

@ubaldus ubaldus marked this pull request as draft September 4, 2020 09:30
@ubaldus ubaldus marked this pull request as ready for review September 4, 2020 14:37
@bokolob
Copy link

bokolob commented Sep 5, 2020

Let’s wait for pulkin

@pulkin
Copy link
Owner

pulkin commented Sep 6, 2020

Can you give more details on this? Did you test it? What formats it supports? Where does it output sound? Can you play it as a voice mail?

@ens4dz
Copy link

ens4dz commented Sep 6, 2020

I test to record in default amr format it's works ok.
recording in mp3 halted the board
palying amr,mp3 files is ok
aac not tested
speaker volume is ok but delay about 0.3s to change from last volume value.

@ens4dz
Copy link

ens4dz commented Sep 7, 2020

there are a bug, when audio.play_start no existed file, you must run audio.play_stop() first

>>> audio.play_start("/t/no_existe_file.amr",15)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot play audio file
>>> audio.play_start("/t/2.amr",15)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot play audio file
>>> audio.play_stop()
>>> audio.play_start("/t/2.amr",15)
>>> audio.play_stop()
>>> audio.play_start("/t/2.amr",15)
>>>

you can't record after answer a call:

>>> cellular.answer()
>>> audio.record_start("/t/2.amr")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot record audio file

but you can start record before answer
it record only sound from mic, not the caller voice

>>> audio.record_start("/t/2.amr")
>>> cellular.answer()
>>> audio.record_stop()

@ens4dz
Copy link

ens4dz commented Sep 7, 2020

To get sound, you need only to solder two wires from old headphone to spk_n , spk_p :

https://raw.githubusercontent.com/Ai-Thinker-Open/GPRS_C_SDK/master/doc/assets/pudding_pin.png

If there is a way to send sound to the caller , that will be a great addition to control device with DTMF

@ubaldus
Copy link
Author

ubaldus commented Sep 7, 2020

The audio output seems to be working for AUDIO_MODE_HANDSET and AUDIO_MODE_LOUDSPEAKER (1,2), both on the speaker pins, not very sure but the only difference I could appreciate is maybe that LOUDSPEAKER is a little louder than HANDSET?

@ubaldus ubaldus marked this pull request as draft September 7, 2020 12:35
@ubaldus
Copy link
Author

ubaldus commented Sep 7, 2020

there are a bug, when audio.play_start no existed file, you must run audio.play_stop() first

>>> audio.play_start("/t/no_existe_file.amr",15)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot play audio file
>>> audio.play_start("/t/2.amr",15)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot play audio file
>>> audio.play_stop()
>>> audio.play_start("/t/2.amr",15)
>>> audio.play_stop()
>>> audio.play_start("/t/2.amr",15)
>>>

yep, AUDIO_Stop() missing in case AUDIO_Play return error.

@ubaldus
Copy link
Author

ubaldus commented Sep 7, 2020

Can you give more details on this? Did you test it? What formats it supports? Where does it output sound? Can you play it as a voice mail?

I am testing with AMR122 and it seems to be working fine both for recording and playing, also mp3 playing seems to be working fine (but not recording). As per the voice mail if you mean like an answering machine I think it will not work as it seems to be not supporting audio recording/playing during a call, not even on official AT command set.

@ubaldus ubaldus marked this pull request as ready for review September 7, 2020 12:46
@pulkin
Copy link
Owner

pulkin commented Sep 7, 2020

It seems like we have audio APIs here and there. I do understand the limitations of the SDK but it would be nice if we invent something compatible.

@ubaldus
Copy link
Author

ubaldus commented Sep 7, 2020

I have been checking the AMP audio skin, didn't know about the other one but they seem to be more focusing on tone generation, my idea was to implement the basic support and leave the rest to Python, I am coming from Lua so very very new to Python but I was thinking that maybe we could add a generic audio.play, audio.pause, audio.resume, audio.record support at module level (I mean already in Python in place then C)?

@ubaldus
Copy link
Author

ubaldus commented Sep 14, 2020

Would it make sense maybe to move the audio support at the moment inside modcellular.c as it is specific to this board only?

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

Successfully merging this pull request may close these issues.

4 participants