Hello everyone, I have made an application to send audio by mqqt using the example of AudioStreamer
Then send by mqtt the variable buffers of type list
Now if I receive the variable and play the audio
Now if I receive the variable and play the audio
now, I send the buffers variable to B4J to try to play the audio
and I pass it through mqtt without problems, but
the problem is that when listening to it in B4J the audio sounds noisy and distorted
the audio has this configuration
Does anyone have an idea what it could be?
thanks in advance
B4X:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("1")
buffers.Initialize
timer1.Initialize("timer1", 1000)
End Sub
Private Sub streamer_RecordBuffer (Buffer() As Byte)
buffers.Add(Buffer)
End Sub
Private Sub btnStartRecording_Click
rp.CheckAndRequest(rp.PERMISSION_RECORD_AUDIO)
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
If Result = False Then
xui.MsgboxAsync("No permission", "")
Return
End If
If streamer.PlayerBufferSize = 0 Then
streamer.Initialize("streamer", 22050, True, 8, streamer.VOLUME_MUSIC)
End If
buffers.Clear
streamer.StartRecording
recordingStart = DateTime.Now
timer1.Enabled = True
Timer1_Tick
btnPlay.Enabled = False
End Sub
Private Sub Timer1_Tick
Label1.Text = "Recording: " & _
Round((DateTime.Now - recordingStart) / DateTime.TicksPerSecond) & " seconds"
End Sub
Private Sub btnStopRecording_Click
streamer.StopRecording
timer1.Enabled = False
btnPlay.Enabled = True
Label1.Text = ""
End Sub
Then send by mqtt the variable buffers of type list
B4X:
Private Sub btnPlay_Click
btnStartRecording.Enabled = False
streamer.StartPlaying
For Each b() As Byte In buffers
' streamer.Write(b)
Next
' send buffers
CallSub3(Qmtt,"enviar_a_MQQT_chat",buffers,"Master")
streamer.Write(Null) 'when this "message" will be processed, the player will stop.
End Sub
Now if I receive the variable and play the audio
B4X:
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Try
mensaje_recibido(Topic,Payload)
Catch
End Try
End Sub
Sub mensaje_recibido( Topic As String, Payload() As Byte)
Dim obj As Object
obj = serializator.ConvertBytesToObject(Payload)
Dim mensajesllegado As List = obj
CallSub2(B4XPages.MainPage,"suena_mensaje",mensajesllegado)
End Sub
Now if I receive the variable and play the audio
B4X:
Public Sub suena_mensaje(mensaje As List)
ToastMessageShow("LLegando mensaje",True)
btnStartRecording.Enabled = False
streamer.StartPlaying
For Each b() As Byte In mensaje
streamer.Write(b)
Next
streamer.Write(Null) 'when this "message" will be processed, the player will stop.
End Sub
now, I send the buffers variable to B4J to try to play the audio
and I pass it through mqtt without problems, but
the problem is that when listening to it in B4J the audio sounds noisy and distorted
B4X:
Private Sub PlayBytes(Bytes() As Byte)
Dim AIS As JavaObject = jAudioTrack2_Utils.NewAudioInputStreamFromBytes(Bytes,AudioFormat)
PlayStream1.Start(SDL,AIS)
End Sub
Public Sub ListToBytes(list As List) As Byte()
Dim o As OutputStream
o.InitializeToBytesArray(0)
Dim b() As Byte
For i = 0 To list.Size - 1
b = list.Get(i)
o.WriteBytes(b, 0, b.Length)
Next
Dim retB() As Byte = o.ToBytesArray
o.Close
Return retB
End Sub
the audio has this configuration
B4X:
'Create an Audioformat Instance
Dim SampleRateHz As Float = 22050
Dim SampleSizeInBits As Int = 8
Dim ChannelConfig As Int = 1
AudioFormat = jAudioRecord2_Utils.NewAudioFormat(SampleRateHz,SampleSizeInBits,ChannelConfig,True, False)
Does anyone have an idea what it could be?
thanks in advance
Last edited: