<commit_before>'use strict'

import ffmpeg from 'fluent-ffmpeg'
import path from 'path'
import fs from 'fs'

import Command from '../interfaces/command'

class Record extends Command {
  constructor () {
    super({
      usage: '%CMD%',
      description: 'Start recording a session.',
      args: 0
    })
  }

  async onCommand(bot, message, args) {
    let channels = message.guild.channels.filter((channel) => {
      if (channel.type === 'voice' && channel.members.size > 0) {
        return channel.members.filter(member => member.id === message.author.id).size > 0
      }
    })

    if (channels.size > 0){
      try {
        let channel = channels.values().next().value
        let connection = await channel.join()
        let receiver = connection.createReceiver()

        connection.on('speaking', (member, speaking) => {
          if (speaking) {
            let homedir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']
            let stream = fs.createWriteStream(path.join(homedir, `${member.id}-${Date.now()}.mp3`))

            stream.on('error', console.error)

            ffmpeg(receiver.createPCMStream(member))
              .inputFormat('s32le')
              .format('s32le')
              .audioCodec('libmp3lame')
              .audioBitrate(320)
              .audioChannels(2)
              .audioFrequency(48000)
              .pipe(stream)
          }
        })
      } catch (err) {
        console.error(err)
      }
    }
  }
}

export default Record
<commit_msg>Fixed the pitch issue after extensive debugging and Googling. Thank god.<commit_after>'use strict'

import ffmpeg from 'fluent-ffmpeg'
import path from 'path'
import fs from 'fs'

import Command from '../interfaces/command'

class Record extends Command {
  constructor () {
    super({
      usage: '%CMD%',
      description: 'Start recording a session.',
      args: 0
    })
  }

  async onCommand(bot, message, args) {
    let channels = message.guild.channels.filter((channel) => {
      if (channel.type === 'voice' && channel.members.size > 0) {
        return channel.members.filter(member => member.id === message.author.id).size > 0
      }
    })

    if (channels.size > 0){
      try {
        let channel = channels.values().next().value
        let connection = await channel.join()
        let receiver = connection.createReceiver()

        connection.on('speaking', (member, speaking) => {
          if (speaking) {
            let homedir = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME']
            let stream = fs.createWriteStream(path.join(homedir, `${member.id}-${Date.now()}.mp3`))

            stream.on('error', console.error)

            ffmpeg(receiver.createPCMStream(member))
              .inputFormat('s32le')
              .format('mp3')
              .audioCodec('libmp3lame')
              .audioBitrate(320)
              .audioChannels(2)
              .audioFrequency(48000)
              .audioFilters('asetrate=r=48K')
              .pipe(stream)
          }
        })
      } catch (err) {
        console.error(err)
      }
    }
  }
}

export default Record

{'fraction_non_alphanumeric': 0.1386861313868613, 'fraction_numerical': 0.01364646144081244, 'mean_word_length': 2.1300893743793448, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2605341', 'n_tokens_mistral': 948, 'n_tokens_neox': 911, 'n_words': 201}