-2

I have recorded one audio file and I am converting that file into base64 format.Now I want to write this audio file into a fifo file. Code is written below:

import os 
import base64
import select
os.system("mkfifo audio1.fifo")
with open("audio1.fifo") as fifo:
     select.select([fifo],[],[fifo])
     with open("out1.wav","rb") as audioFile:
         str = base64.b64encode(audioFile.read())
         fifo.write(str)

But above code only creating fifo file but not writing anything in it.Plz give any suggestions.

  • Did you open it for reading on the other side? – MisterMiyagi Jan 13 '20 at 06:31
  • What are you using as the reader? And how do how do start/run that please? – Mark Setchell Jan 13 '20 at 08:14
  • @MisterMiyagi I have opened fifo file to which data need to be written.What do u mean by other side sir?? – kunal Jan 13 '20 at 12:21
  • A FIFO is meant to exchange data, not to store it. It usually cannot be written to if there is nothing on the other end to receive the data. To quote from [the linux man page](http://man7.org/linux/man-pages/man7/fifo.7.html): "The FIFO must be opened on both ends (reading and writing) before data can be passed." – MisterMiyagi Jan 13 '20 at 12:26
  • @MisterMiyagi Can u plz tell me if i want to read the audio data from uart of raspberry pi 3b and play the same data at the same time at 3.5mm audio jack (By considering that i am transmitting some audio data from transmitter side Raspberry pi).How to do it?? – kunal Jan 13 '20 at 13:54
  • Does this answer your question? [Receiving data through uart in raspberry pi 3b](https://stackoverflow.com/questions/59676120/receiving-data-through-uart-in-raspberry-pi-3b) – 0andriy Jan 13 '20 at 21:36
  • @0andriy No sir i didn't get answer – kunal Jan 14 '20 at 05:06
  • You created duplicated questions – 0andriy Jan 14 '20 at 10:49
  • @0andriy No sir not exact duplicate questions. Here i want to write a recorded file into fifo file but in another question I wanted to write fifo file while receiving from UART OF RPI – kunal Jan 14 '20 at 15:09

1 Answers1

0

Use + model can at the same time support read and write

import base64
import select
os.system("mkfifo audio1.fifo")
with open("audio1.fifo", "wb") as fifo:
     select.select([fifo],[],[fifo])
     with open("out1.wav","rb") as audioFile:
         str = base64.b64encode(audioFile.read())
         fifo.write(str)

The same time read and write two different files:

# maker sure the be read file's has some data.
with open("a.file", "w") as fp:
    fp.write("some data")

# now a.file has some data, we create a b.file for write the a.file's data.
with open("b.file", "w") as write_fp, open("a.file", "r") as read_fp:
    write_fp.write(read_fp.read())

# for bytes data
with open("b.file", "wb") as write_fp, open("a.file", "rb") as read_fp:
    write_fp.write(read_fp.read())
DustyPosa
  • 463
  • 2
  • 8