Android Question Problem audioStream.VOLUME_MUSIC

mohammad be

Member
Hello everyone

I use this code to record audio and play audio
But my own voice repeats itself

what's the reason?

B4X:
    audioStream.Initialize("AudioStream", 22050, False, 16, audioStream.VOLUME_MUSIC)
    audioStream.StartPlaying
    audioStream.StartRecording
 

mohammad be

Member
Playing and recording at the same time will be problematic. The microphone will capture the speakers output.
Hello
I know
I have a voice chat app in mode VOLUME_VOICE_CALL
It works well but is reflective in sound mode VOLUME_MUSIC

What do apps like WhatsApp do in audio mode?
That my voice does not return?
 
Upvote 0

Midimaster

Active Member
Licensed User
I'm not 100%, but some questions:

Why do you play what you have recorded? You hear your own voice. So it looks like you have sent it to OUT...

It's a whole different thing, not to record what is on the speaker. f.e. music or other chat member. But your own voice?

Is there a reason for simulanously use Recorder and Player? You could mute recoding when there is a chat coming in.

What exactly do you send to the AudioStreamer?

Did you already try to use two objects? One for the player one for the recording?

Did you read this? https://www.b4x.com/android/forum/threads/speakerphone.84707/#post-537127
 
Last edited:
Upvote 0

mohammad be

Member
I'm not 100%, but some questions:

Why do you play what you have recorded? You hear your own voice. So it looks like you have sent it to OUT...

It's a whole different thing, not to record what is on the speaker. f.e. music or other chat member. But your own voice?

Is there a reason for simulanously use Recorder and Player? You could mute recoding when there is a chat coming in.

What exactly do you send to the AudioStreamer?

Did you already try to use two objects? One for the player one for the recording?

Did you read this? https://www.b4x.com/android/forum/threads/speakerphone.84707/#post-537127
?
Tanks
 
Upvote 0

mohammad be

Member
I'm not 100%, but some questions:

Why do you play what you have recorded? You hear your own voice. So it looks like you have sent it to OUT...

It's a whole different thing, not to record what is on the speaker. f.e. music or other chat member. But your own voice?

Is there a reason for simulanously use Recorder and Player? You could mute recoding when there is a chat coming in.

What exactly do you send to the AudioStreamer?

Did you already try to use two objects? One for the player one for the recording?

Did you read this? https://www.b4x.com/android/forum/threads/speakerphone.84707/#post-537127
Hello
Yes, I use two objects, one for playback and one for recording, but the sound is reflected
B4X:
Sub Service_Create
    audioStream2.Initialize("AudioStream", 22050, False, 16, audioStream2.VOLUME_MUSIC)
    audioStream.Initialize("AudioStream", 22050, False, 16,audioStream.VOLUME_VOICE_CALL)
    SetEchoCanceler
End Sub
Sub SetEchoCanceler
   Dim echo As JavaObject
   echo.InitializeStatic("android/media/audiofx/AcousticEchoCanceler".Replace("/", "."))
   If echo.RunMethod("isAvailable", Null) = True Then
     Dim r As Reflector
     r.Target = streamer
     Dim AudioRecord As JavaObject = r.GetField("audioRecord")
     echo.RunMethod("create", Array(AudioRecord.RunMethod("getAudioSessionId", Null)))
     Log("echo set")
   Else
     Log("Echo not available")
   End If
End Sub
Private Sub socket1_Connected (Successful As Boolean)
    If Successful Then
        StartAStream(socket1.InputStream, socket1.OutputStream)
    End If
End Sub
Private Sub socket2_Connected (Successful As Boolean)
    If Successful Then
        StartAStream2(socket2.InputStream, socket2.OutputStream)
    End If
End Sub
Private Sub StartAStream (In As InputStream, out As OutputStream)
    Log("StartAStream")
    astream.InitializePrefix(In, True, out, "astream")
    SetSpeaker(True)
    SetMute(True)
End Sub
Private Sub StartAStream2 (In As InputStream, out As OutputStream)
    Log("StartAStream2")
    astream2.InitializePrefix(In, True, out, "astream2")
    SetSpeaker(True)
    SetMute(True)
End Sub
Sub astream_NewData (Buffer() As Byte)
    Dim mm11 As MyMessage
    mm11.Initialize
    mm11=ser.ConvertBytesToObject(Buffer)
    Dim bb11() As Byte
    bb11=mm11.Voice
    Select mm11.Code
        Case 1 'SetIp
            Starter.CALL_MYIP=mm11.Sen
            SendIp(Starter.CALL_MYIP,mm11.rec)
        Case 2 'Voice
            If Speaker Then
                audioStream.Write(bb11)
            Else
                audioStream2.Write(bb11)
            End If
'        Case 3
'            If IsPaused(Chat1) Then
'                EndCall
'            Else
'                CallSub(Calls,"CallChatCancel")
'            End If
    End Select
End Sub
Sub astream2_NewData (Buffer() As Byte)
    Dim mm11 As MyMessage
    mm11.Initialize
    mm11=ser.ConvertBytesToObject(Buffer)
    Dim bb11() As Byte
    bb11=mm11.Voice
    Select mm11.Code
        Case 1 'SetIp
            Starter.CALL_MYIP=mm11.Sen
            SendIp(Starter.CALL_MYIP,mm11.rec)
        Case 2 'Voice
            If Speaker Then
                audioStream.Write(bb11)
            Else
                audioStream2.Write(bb11)
            End If
'        Case 3
'            If IsPaused(Chat1) Then
'                EndCall
'            Else
'                CallSub(Calls,"CallChatCancel")
'            End If
    End Select
End Sub
Sub AudioStream_RecordBuffer (Data() As Byte)
    Select Starter.CALL_STATE
        Case "IN"
            Dim mm11 As MyMessage
            mm11.Initialize
            mm11.Code=2
            mm11.Sen=Starter.CALL_MYIP
            mm11.Rec=Starter.CALL_IP
            mm11.Voice=Data
            Dim bb11() As Byte
            bb11=ser.ConvertObjectToBytes(mm11)
            astream2.Write(bb11)
'            CallSub3(FirebaseMessaging,"sendVoice",Starter.CALL_ID,mm11)
        Case "OUT"
            Dim mm12 As MyMessage
            mm12.Initialize
            mm12.Code=2
            mm12.Sen=Starter.CALL_MYIP
            mm12.Rec=Starter.CALL_IP
            mm12.Voice=Data
            Dim bb12() As Byte
            bb12=ser.ConvertObjectToBytes(mm12)
            astream.Write(bb12)
'            CallSub3(FirebaseMessaging,"sendVoice",Starter.CALL_ID,mm12)
    End Select
End Sub
Sub SetSpeaker(status As Boolean)
    Speaker=status
    If status Then
        audioStream2.StopPlaying
        audioStream.StartPlaying
    Else
        audioStream.StopPlaying
        audioStream2.StartPlaying
    End If
End Sub
 
Last edited:
Upvote 0

mohammad be

Member
Better to check with [email protected] :)
Hello again
I tested on Android 5 in mode
The sound is not reflected
But in Android, more than 7 sounds are reflected, should it?
audioStream2.Initialize2(??????,"AudioStream", 22050, False, 16,audioStream.VOLUME_MUSIC)
audio source set?
B4X:
    If Utils.GetSDK>=23 Then
        audioStream.Initialize2(???,"AudioStream", 22050, False, 16,audioStream.VOLUME_VOICE_CALL)
        audioStream2.Initialize2(???,"AudioStream", 22050, False, 16,audioStream.VOLUME_MUSIC)
    Else
        audioStream.Initialize2(0,"AudioStream", 22050, False, 16,audioStream.VOLUME_VOICE_CALL)
        audioStream2.Initialize2(0,"AudioStream", 22050, False, 16,audioStream.VOLUME_MUSIC)
    End If
 
Upvote 0

Midimaster

Active Member
Licensed User
B4X:
    If Utils.GetSDK>=23 Then
        audioStream.Initialize2(???,"AudioStream", 22050, False, 16,audioStream.VOLUME_VOICE_CALL)
        audioStream2.Initialize2(???,"AudioStream", 22050, False, 16,audioStream.VOLUME_MUSIC)
...
Did you read this about the constants of Audio-Source?
https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
The mode 7 is interesting. But I have to tell you, I never used AudioStreamer with Initialize2

I'm again not 100% sure, that I understand your code, but why do you sent any Bytes to the (first) AudioStream object, if this is the recording object?
 
Upvote 0

mohammad be

Member
Did you read this about the constants of Audio-Source?
https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
The mode 7 is interesting. But I have to tell you, I never used AudioStreamer with Initialize2

I'm again not 100% sure, that I understand your code, but why do you sent any Bytes to the (first) AudioStream object, if this is the recording object?
hello, because I am sending bytes to the server through the socket and the server is sending them to another user.
 
Upvote 0

mohammad be

Member
ث
Did you read this about the constants of Audio-Source?
https://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
The mode 7 is interesting. But I have to tell you, I never used AudioStreamer with Initialize2

I'm again not 100% sure, that I understand your code, but why do you sent any Bytes to the (first) AudioStream object, if this is the recording object?
I use two objects, one in internal speaker mode and one external when the user presses the speaker button, I use the second object and the received information enters the second object and in the internal speaker mode the first object is used.
 
Upvote 0
Top