Some data getting lost when using PySerial’s read() function /u/supersonic_528 Python Education

Some data getting lost when using PySerial’s read() function /u/supersonic_528 Python Education

I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening?

Now, to debug the above issue, I added a print statement just before my read() function. So it looks like:

self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received

In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time).

Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output).

in_waiting = 3896

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea

in_waiting = 3820

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea

in_waiting = 3744

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e

So my questions are…

What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)?

submitted by /u/supersonic_528
[link] [comments]

​r/learnpython I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening? Now, to debug the above issue, I added a print statement just before my read() function. So it looks like: self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time). Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output). in_waiting = 3896 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3820 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3744 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e So my questions are… What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)? submitted by /u/supersonic_528 [link] [comments] 

I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening?

Now, to debug the above issue, I added a print statement just before my read() function. So it looks like:

self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received

In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time).

Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output).

in_waiting = 3896

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea

in_waiting = 3820

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea

in_waiting = 3744

12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e

So my questions are…

What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)?

submitted by /u/supersonic_528
[link] [comments]  I have a Python program running on my PC that is receiving serial data from a microcontroller. The serial data is basically from the UART (with baud rate set to 921,600), where each packet is 76 bytes long, and packets are being sent at the rate of 800 packets per second. In my Python program, this is implemented by calling the read() function of Serial as read(76). However, I am seeing that after receiving a few hundred packets, one of the packets is missing a few bytes in the middle. Any idea why this might be happening? Now, to debug the above issue, I added a print statement just before my read() function. So it looks like: self.serialInst = serial.Serial(self.COM_PORT, BAUD_RATE, bytesize=8, timeout=0.4) ……. ……. print(“nin_waiting = ” + str(self.serialInst.in_waiting), file = self.dbgFile) packet = self.serialInst.read(76) # then print the bytes of the packet received In the output that is printed, I see that the value of in_waiting starts with a rather large number 3892 (when the first packet has been received). Then after each packet is received, I see the value reducing by 76 (most of the time). Below is the output showing the last 3 packets, where the last packet is missing a few bytes (after 1b comes 3f). All the packets should have exactly same data (for this experimental run and output). in_waiting = 3896 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3820 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 01 ea in_waiting = 3744 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 3f 40 41 42 43 44 45 01 ea 12 58 08 08 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e So my questions are… What might cause some bytes to be missing in the last packet? Why does in_waiting have a high value of 3892 at the beginning (that is, after receiving the very first packet of size 76 bytes)? submitted by /u/supersonic_528 [link] [comments]

Read more

At what point can I just start learning the things I’m interested in? /u/jdaniel560 Python Education

At what point can I just start learning the things I’m interested in? /u/jdaniel560 Python Education

I am currently on Day 60 of Angela Yu’s “100 Days of Code” Python boot camp and while I still love coding, my enthusiasm for the course has waned with the course’s focus shifting to WebDev, Flask, CSS, etc. My interests and project ideas right now are primarily in data science, machine learning, and GIS. I understand that everything is interconnected but am I hampering my long-term development skills if I just start diving into what I see as the “fun stuff”, creating projects I think would help me in my current job, without completing the second half of the course material? I guess to pose the question in an alternate way, what do I HAVE to know before jumping ship from the more structured curriculum?

submitted by /u/jdaniel560
[link] [comments]

​r/learnpython I am currently on Day 60 of Angela Yu’s “100 Days of Code” Python boot camp and while I still love coding, my enthusiasm for the course has waned with the course’s focus shifting to WebDev, Flask, CSS, etc. My interests and project ideas right now are primarily in data science, machine learning, and GIS. I understand that everything is interconnected but am I hampering my long-term development skills if I just start diving into what I see as the “fun stuff”, creating projects I think would help me in my current job, without completing the second half of the course material? I guess to pose the question in an alternate way, what do I HAVE to know before jumping ship from the more structured curriculum? submitted by /u/jdaniel560 [link] [comments] 

I am currently on Day 60 of Angela Yu’s “100 Days of Code” Python boot camp and while I still love coding, my enthusiasm for the course has waned with the course’s focus shifting to WebDev, Flask, CSS, etc. My interests and project ideas right now are primarily in data science, machine learning, and GIS. I understand that everything is interconnected but am I hampering my long-term development skills if I just start diving into what I see as the “fun stuff”, creating projects I think would help me in my current job, without completing the second half of the course material? I guess to pose the question in an alternate way, what do I HAVE to know before jumping ship from the more structured curriculum?

submitted by /u/jdaniel560
[link] [comments]  I am currently on Day 60 of Angela Yu’s “100 Days of Code” Python boot camp and while I still love coding, my enthusiasm for the course has waned with the course’s focus shifting to WebDev, Flask, CSS, etc. My interests and project ideas right now are primarily in data science, machine learning, and GIS. I understand that everything is interconnected but am I hampering my long-term development skills if I just start diving into what I see as the “fun stuff”, creating projects I think would help me in my current job, without completing the second half of the course material? I guess to pose the question in an alternate way, what do I HAVE to know before jumping ship from the more structured curriculum? submitted by /u/jdaniel560 [link] [comments]

Read more

Accessing Django Model in program? /u/Rapid1898 Python Education

Accessing Django Model in program? /u/Rapid1898 Python Education

Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing

This is my models.py

from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True)

And this is my temp.py

“` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue

worker = Queue.objects.all() print(worker) “`

But when i run the temp.py program i get this error

(Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package

submitted by /u/Rapid1898
[link] [comments]

​r/learnpython Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing This is my models.py from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True) And this is my temp.py “` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue worker = Queue.objects.all() print(worker) “` But when i run the temp.py program i get this error (Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package submitted by /u/Rapid1898 [link] [comments] 

Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing

This is my models.py

from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True)

And this is my temp.py

“` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue

worker = Queue.objects.all() print(worker) “`

But when i run the temp.py program i get this error

(Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package

submitted by /u/Rapid1898
[link] [comments]  Hello – i have created a Model in the models.py and now i wanted to access the model with another seperate program which is called temp.py for testing This is my models.py from django.db import models class Queue(models.Model): timestamp = models.CharField(max_length = 50, blank = True) firstName = models.CharField(max_length = 200, blank = True) And this is my temp.py “` import django import os os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “gpt.settings”) django.setup() from .models import Queue worker = Queue.objects.all() print(worker) “` But when i run the temp.py program i get this error (Django) C:DEVFiverrORDERcolli239gptgpp>python temp.py Traceback (most recent call last): File “C:DEVFiverrORDERcolli239gptgpptemp.py”, line 1, in <module> from .models import Queue ImportError: attempted relative import with no known parent package submitted by /u/Rapid1898 [link] [comments]

Read more

Is the University of Helsinki MOOC Python course exam free? /u/JebusdeMazaret Python Education

Is the University of Helsinki MOOC Python course exam free? /u/JebusdeMazaret Python Education

I just completed the first part, and I was thinking about to get the certificate, so yeah, Is there a price for the exam?

submitted by /u/JebusdeMazaret
[link] [comments]

​r/learnpython I just completed the first part, and I was thinking about to get the certificate, so yeah, Is there a price for the exam? submitted by /u/JebusdeMazaret [link] [comments] 

I just completed the first part, and I was thinking about to get the certificate, so yeah, Is there a price for the exam?

submitted by /u/JebusdeMazaret
[link] [comments]  I just completed the first part, and I was thinking about to get the certificate, so yeah, Is there a price for the exam? submitted by /u/JebusdeMazaret [link] [comments]

Read more

How can I exit the program on specified user input when in another window? /u/timosaurus-rex Python Education

How can I exit the program on specified user input when in another window? /u/timosaurus-rex Python Education

I have a program that plays a mobile game on an emulator for me, so the first thing it does is open another window over VSCode.

It moves the mouse around quite fast so I can’t always get back to VSCode to exit the program.

Can someone help me figure out a way of having the program recognise a specified user input (like pressing ‘q’ or something) even when I’m in another window and then exiting the program when that is deteced?

I was thinking some kind of multi-threaded monitor daemon to just constantly check if ‘q’ has been pressed but I’m quite new to this so would love to hear of any better suggestions.

FYI Ctrl+C doesn’t work when I’m in another window, already tried that.

submitted by /u/timosaurus-rex
[link] [comments]

​r/learnpython I have a program that plays a mobile game on an emulator for me, so the first thing it does is open another window over VSCode. It moves the mouse around quite fast so I can’t always get back to VSCode to exit the program. Can someone help me figure out a way of having the program recognise a specified user input (like pressing ‘q’ or something) even when I’m in another window and then exiting the program when that is deteced? I was thinking some kind of multi-threaded monitor daemon to just constantly check if ‘q’ has been pressed but I’m quite new to this so would love to hear of any better suggestions. FYI Ctrl+C doesn’t work when I’m in another window, already tried that. submitted by /u/timosaurus-rex [link] [comments] 

I have a program that plays a mobile game on an emulator for me, so the first thing it does is open another window over VSCode.

It moves the mouse around quite fast so I can’t always get back to VSCode to exit the program.

Can someone help me figure out a way of having the program recognise a specified user input (like pressing ‘q’ or something) even when I’m in another window and then exiting the program when that is deteced?

I was thinking some kind of multi-threaded monitor daemon to just constantly check if ‘q’ has been pressed but I’m quite new to this so would love to hear of any better suggestions.

FYI Ctrl+C doesn’t work when I’m in another window, already tried that.

submitted by /u/timosaurus-rex
[link] [comments]  I have a program that plays a mobile game on an emulator for me, so the first thing it does is open another window over VSCode. It moves the mouse around quite fast so I can’t always get back to VSCode to exit the program. Can someone help me figure out a way of having the program recognise a specified user input (like pressing ‘q’ or something) even when I’m in another window and then exiting the program when that is deteced? I was thinking some kind of multi-threaded monitor daemon to just constantly check if ‘q’ has been pressed but I’m quite new to this so would love to hear of any better suggestions. FYI Ctrl+C doesn’t work when I’m in another window, already tried that. submitted by /u/timosaurus-rex [link] [comments]

Read more

Why does Numpy apply functions in a way that loses array dimensionality? /u/Schnauzerofdoom Python Education

Why does Numpy apply functions in a way that loses array dimensionality? /u/Schnauzerofdoom Python Education

In other words, I’m wondering why keepdims is False by default on functions like np.max() or np.sum() when you supply an axis. Seems to me like retaining dimensions would be preferable in pretty much every case but I don’t have enough experience to know if that’s actually true. In fact I can’t even figure out why keepdims would need to be an argument to begin with. If I wanted to sum some data like:

inputs =

[[1 2 3]

[1 2 3]

[1 2 3]]

And let’s say I ran

np.sum(inputs, axis=1)

Why would I ever want the output to be this:

[3 6 9]

Rather than this?

[[3]

[6]

[9]]

Even if you want it that way you can just transpose it afterward, right? I feel like there must be a good reason Numpy does this but I can’t figure out why.

submitted by /u/Schnauzerofdoom
[link] [comments]

​r/learnpython In other words, I’m wondering why keepdims is False by default on functions like np.max() or np.sum() when you supply an axis. Seems to me like retaining dimensions would be preferable in pretty much every case but I don’t have enough experience to know if that’s actually true. In fact I can’t even figure out why keepdims would need to be an argument to begin with. If I wanted to sum some data like: inputs = [[1 2 3] [1 2 3] [1 2 3]] And let’s say I ran np.sum(inputs, axis=1) Why would I ever want the output to be this: [3 6 9] Rather than this? [[3] [6] [9]] Even if you want it that way you can just transpose it afterward, right? I feel like there must be a good reason Numpy does this but I can’t figure out why. submitted by /u/Schnauzerofdoom [link] [comments] 

In other words, I’m wondering why keepdims is False by default on functions like np.max() or np.sum() when you supply an axis. Seems to me like retaining dimensions would be preferable in pretty much every case but I don’t have enough experience to know if that’s actually true. In fact I can’t even figure out why keepdims would need to be an argument to begin with. If I wanted to sum some data like:

inputs =

[[1 2 3]

[1 2 3]

[1 2 3]]

And let’s say I ran

np.sum(inputs, axis=1)

Why would I ever want the output to be this:

[3 6 9]

Rather than this?

[[3]

[6]

[9]]

Even if you want it that way you can just transpose it afterward, right? I feel like there must be a good reason Numpy does this but I can’t figure out why.

submitted by /u/Schnauzerofdoom
[link] [comments]  In other words, I’m wondering why keepdims is False by default on functions like np.max() or np.sum() when you supply an axis. Seems to me like retaining dimensions would be preferable in pretty much every case but I don’t have enough experience to know if that’s actually true. In fact I can’t even figure out why keepdims would need to be an argument to begin with. If I wanted to sum some data like: inputs = [[1 2 3] [1 2 3] [1 2 3]] And let’s say I ran np.sum(inputs, axis=1) Why would I ever want the output to be this: [3 6 9] Rather than this? [[3] [6] [9]] Even if you want it that way you can just transpose it afterward, right? I feel like there must be a good reason Numpy does this but I can’t figure out why. submitted by /u/Schnauzerofdoom [link] [comments]

Read more

Best language to develop mobile apps which run Python? /u/Gotz16 Python Education

Best language to develop mobile apps which run Python? /u/Gotz16 Python Education

Hi, I want to code a lot of mobile Apps that runs python scrypts so bad but I am not sure if I should learn Kotlin, React Native or what. I really dont mind about the language itself but its compatibility with Python and how easy it would be to run it on the language. Thanks in advice!

submitted by /u/Gotz16
[link] [comments]

​r/learnpython Hi, I want to code a lot of mobile Apps that runs python scrypts so bad but I am not sure if I should learn Kotlin, React Native or what. I really dont mind about the language itself but its compatibility with Python and how easy it would be to run it on the language. Thanks in advice! submitted by /u/Gotz16 [link] [comments] 

Hi, I want to code a lot of mobile Apps that runs python scrypts so bad but I am not sure if I should learn Kotlin, React Native or what. I really dont mind about the language itself but its compatibility with Python and how easy it would be to run it on the language. Thanks in advice!

submitted by /u/Gotz16
[link] [comments]  Hi, I want to code a lot of mobile Apps that runs python scrypts so bad but I am not sure if I should learn Kotlin, React Native or what. I really dont mind about the language itself but its compatibility with Python and how easy it would be to run it on the language. Thanks in advice! submitted by /u/Gotz16 [link] [comments]

Read more

turning my multithreading code into multiprocessing /u/qhelspil Python Education

turning my multithreading code into multiprocessing /u/qhelspil Python Education

i want to record 2 audios at the same time.

using multithreadind this code works fine

import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

using multiprocessing, i just replaced the classes and the result is

import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”)

however it is not recording anything, it prints ‘recordings completed’ instantly

what am i doing wrong?

thanks

submitted by /u/qhelspil
[link] [comments]

​r/learnpython i want to record 2 audios at the same time. using multithreadind this code works fine import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) using multiprocessing, i just replaced the classes and the result is import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”) however it is not recording anything, it prints ‘recordings completed’ instantly what am i doing wrong? thanks submitted by /u/qhelspil [link] [comments] 

i want to record 2 audios at the same time.

using multithreadind this code works fine

import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”)

using multiprocessing, i just replaced the classes and the result is

import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”)

however it is not recording anything, it prints ‘recordings completed’ instantly

what am i doing wrong?

thanks

submitted by /u/qhelspil
[link] [comments]  i want to record 2 audios at the same time. using multithreadind this code works fine import sounddevice as sd from scipy.io.wavfile import write import numpy as np import threading fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording first audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() # Wait until the recording is finished print(“First recording stopped.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”First audio saved as {filename}”) thread1 = threading.Thread(target=record_audio, args=(fs, duration, filename1)) thread2 = threading.Thread(target=record_audio, args=(fs, duration, filename2)) thread1.start() thread2.start() thread1.join() thread2.join() print(“recordings complete.”) using multiprocessing, i just replaced the classes and the result is import sounddevice as sd from scipy.io.wavfile import write import numpy as np from multiprocessing import Process fs = 44100 duration = 5 filename1 = ‘output.wav’ filename2 = ‘second_output.wav’ def record_audio(fs, duration, filename): print(f”Recording audio to {filename}…”) recording = sd.rec(int(duration * fs), samplerate=fs, channels=2, dtype=’float64′) sd.wait() print(f”Recording stopped for {filename}.”) recording = np.int16(recording * 32767) write(filename, fs, recording) print(f”Audio saved as {filename}”) process1 = Process(target=record_audio, args=(fs, duration, filename1)) process2 = Process(target=record_audio, args=(fs, duration, filename2)) process1.start() process2.start() process1.join() process2.join() print(“recordings complete.”) however it is not recording anything, it prints ‘recordings completed’ instantly what am i doing wrong? thanks submitted by /u/qhelspil [link] [comments]

Read more