I used this example to record audio from a voice channel. Everything works, at the output I get a separate audio track for each speaking user.
Next, I want to overlay audio files on top of each other and glue the conversation in the channel into one file, but as a result, all the voices in the file sound almost simultaneously, although in fact the users speak in turn.
This is because py-cord
does not record silence at the beginning and end of the user's audio recording.
Thus, if 3 people say something in turn, then as a result the recordings of their speech will have different lengths and because of this they are mixed into one heap.
How can I record audio files of the same length for all users in a channel?
UPD:
This is a fragment of the recv_decoded_audio
method from the discord.VoiceClient
class. From here it can be understood that the silence between the user's speech is added by calculating the time between individual fragments of the user's speech.
def recv_decoded_audio(self, data):
if data.ssrc not in self.user_timestamps:
self.user_timestamps.update({data.ssrc: data.timestamp})
# Add silence when they were not being recorded.
silence = 0
else:
silence = data.timestamp - self.user_timestamps[data.ssrc] - 960
self.user_timestamps[data.ssrc] = data.timestamp
data.decoded_data = (
struct.pack("<h", 0) * silence * opus._OpusStruct.CHANNELS
+ data.decoded_data
)
. . .
In this case, it makes sense that I can replace the line silence = 0
with this code:
. . .
self.start_recording_timestamp = int(datetime.now().timestamp())
. . .
silence = data.timestamp - self.start_recording_timestamp
And this will indeed add the user's silence at the beginning of the recording, but for some reason, instead of 5 seconds, a minute of silence is immediately added there.
How, in this case, is it correct to implement the addition of silence at the beginning of the recording, while not changing the library files?
How to correctly calculate the silence time at the beginning of a recording?
from Pycord Voice Recieve: How to record silence at the beginning and end of a recording?
No comments:
Post a Comment