zeyus/Python3BlueBox

Running errors and what I think are logical errors

mostcat opened this issue · 5 comments

env:

  • Win10
  • Python 3.9.4 (tags/v3.9.4:1f2e308, Apr 4 2021, 13:27:16) [MSC v.1928 64 bit (AMD64)] on win32

The error is concentrated in this sentence:

 stream.write(array.array('f',
                             ((volume * math.sin(2.0 * math.pi * i * tone[0] / float(sr)) + volume * math.sin(2.0 * math.pi * i * tone[1] / float(sr)))
                              for i in range(sr*int(length)))).tostring())

Error1:

stream.write(array.array('f',
AttributeError: 'array.array' object has no attribute 'tostring'

Error2:
sr*int(length))
int(length) = int(0.25) = 0


After fixing the above 2 errors, you can dial normally through the phone handset

    commandDTMF = array.array('f',((volume * math.sin(2.0 * math.pi * i * tone[0] / float(sr)) + volume * math.sin(2.0 * math.pi * i * tone[1] / float(sr)))
                                for i in range(int(sr*length)))).tobytes()
    stream.write(commandDTMF)
zeyus commented

Thanks @mostcat now that you've reported this I think what I will do is make a github workflow and add some tests for python 3.9-3.11, I originally wrote this I think it was just after python 3 came out and it was a learning project! But I'm really happy someone else uses it :D

I'll adress those fixes in a couple of days and hopefully make the whole thing a bit more robust. I can ping you on the pull request if you're interested in reviewing it!

I'm happy to be involved in maintaining
Your project has fewer external requirements and smaller installed libraries, so I like it.
Nowadays, there are very few people who can do DTMF, a very niche technology.
I am working on a Raspberry Pi application that connects to PSTN (ordinary telephone) as an amateur.

zeyus commented

Nice, I have a bunch of raspberry pis at home, they're awesome!

And yeah, DTMF is old, but so am I ;)

I've made a PR, it's still 100% WIP but basically the idea is that i will make a cli that is a bit more robust and compatible with the previous implementation (e.g. send a bunch of letters)
but on top of it, now it's modular so it can be loaded by another app easily with the bonus additions of

  • easy backend implementation (if you don't want to use pyaudio)
  • easy MF generator addition, you can create your own MF code -> frequency maps
  • tests will be added to make sure things work as they say they do
  • cli will accept pipe/stream input as well

currently I did the audio playback with a blocking implementation and started on a non-blocking implementation which might be useful but it should probably be done with asyncio rather than callbacks (it's just that pyaudio uses callbacks so i'll just start with that, it's probably enough, i think i might just add a simple queue implementation instead which the callback can read from until it runs out!)

you can see the in progress PR here: #4
feel free to comment / ask questions about it :)

zeyus commented

This should be pretty much done. There are some features that are partially implemented, but i'm happy to work on them if they're used, otherwise anyone is free to submit a PR with fixes, additions, tests, etc :)

let me know if you have any issues!!

Your problem is fixed quickly, kudos to you.
I'm recently getting the whole landline dialing system working.
Currently using your DTMF base has been implemented, can achieve off-hook, voice DTMF dialing, play voice on Raspberry Pi 3, basically achieve the basic function of VMS (voice notification) I want, thank you for your contribution.
I will test your new code when I have time.

1fb233f648fdf37de09fc87f18fe840