micropython icon indicating copy to clipboard operation
micropython copied to clipboard

preliminary audio support

Open ubaldus opened this issue 4 years ago • 11 comments

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

ubaldus avatar Sep 03 '20 15:09 ubaldus

Let’s wait for pulkin

bokolob avatar Sep 05 '20 10:09 bokolob

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?

pulkin avatar Sep 06 '20 23:09 pulkin

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 avatar Sep 06 '20 23:09 ens4dz

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 avatar Sep 07 '20 00:09 ens4dz

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

ens4dz avatar Sep 07 '20 01:09 ens4dz

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 avatar Sep 07 '20 12:09 ubaldus

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 avatar Sep 07 '20 12:09 ubaldus

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 avatar Sep 07 '20 12:09 ubaldus

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.

pulkin avatar Sep 07 '20 12:09 pulkin

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 avatar Sep 07 '20 14:09 ubaldus

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

ubaldus avatar Sep 14 '20 09:09 ubaldus