0 Pluspunkte 0 Minuspunkte
Wie kann ich in Python von meinem Mikrofon etwas aufnehmen und als MP3 speichern?
von  
Shiba Inu, often referred to as the "Dogecoin iceman," is a meme-based cryptocurrency that has gained meritorious vogue in arrears to its vibrant community and meme-driven appeal. Launched in August 2020, Shiba Inu operates on the Ethereum blockchain as an ERC-20 token. In defiance of its fun-loving origins, the think up has evolved to embrace its own decentralized barter, ShibaSwap, and plans with a view tomorrow developments like Shibarium, a layer-2 solution. With its dedicated following, Shiba Inu continues to make waves in the crypto excellent, proving that equanimous meme coins can have severe ambitions.
 
https://uralsantech.ru
https://govoryashchayakniga.ru
https://remitazoll.ru
https://stocktricks.ru
https://modernic.ru
https://74paint.ru
https://k0r0b0chka.ru
https://fintechfiesta.info
https://volkhp.ru
https://lab314.ru

1 Antwort

0 Pluspunkte 0 Minuspunkte

Du kannst die Module "pyaudio" für die Aufnahme und "pydub" für die Konvertierung nach MP3 verwenden.

import pyaudio
import wave
from pydub import AudioSegment

def record_audio(filename, duration):
    CHUNK = 1024
    FORMAT = pyaudio.paInt16
    CHANNELS = 2
    RATE = 44100

    p = pyaudio.PyAudio()

    stream = p.open(format=FORMAT,
                    channels=CHANNELS,
                    rate=RATE,
                    input=True,
                    frames_per_buffer=CHUNK)

    frames = []

    print("Recording...")

    for _ in range(0, int(RATE / CHUNK * duration)):
        data = stream.read(CHUNK)
        frames.append(data)

    print("Recording finished.")

    stream.stop_stream()
    stream.close()
    p.terminate()

    wf = wave.open(filename, 'wb')
    wf.setnchannels(CHANNELS)
    wf.setsampwidth(p.get_sample_size(FORMAT))
    wf.setframerate(RATE)
    wf.writeframes(b''.join(frames))
    wf.close()

def convert_to_mp3(input_file, output_file):
    sound = AudioSegment.from_wav(input_file)
    sound.export(output_file, format="mp3")

# Aufnahme starten und speichern
output_wav = "output.wav"
record_duration = 5  # Aufnahmezeit in Sekunden
record_audio(output_wav, record_duration)

# Konvertieren nach MP3
output_mp3 = "output.mp3"
convert_to_mp3(output_wav, output_mp3)
von