still can't get audio to play properly
This commit is contained in:
1 parent
6897b684ee
commit
270ab6799b
3 files changed
+84
-16
No files matched your search
@@ -5,10 +5,13 @@
|
||||
# loop = urwid.MainLoop(fill)
|
||||
# loop.run()
|
||||
|
||||
import subprocess
|
||||
import wave
|
||||
import io
|
||||
|
||||
import SubSonic
|
||||
import pyaudio
|
||||
import pydub
|
||||
|
||||
u = 'pseudo'
|
||||
p = 'telegram9dock-MICHEL'
|
||||
@@ -19,28 +22,62 @@ echidna_id = "937004317800a879f0cddd471fb82387"
|
||||
def play_song(song_id: str):
|
||||
r = conn.stream(song_id)
|
||||
|
||||
# print(len(r.content))
|
||||
p = pyaudio.PyAudio()
|
||||
|
||||
stream_data: bytes = r.content
|
||||
# ogg_data = io.BytesIO(r.content)
|
||||
# audio = pydub.AudioSegment.from_ogg(ogg_data)
|
||||
# # audio.set_sample_width(2)
|
||||
# print("channels", audio.channels)
|
||||
# print("rate", audio.frame_rate)
|
||||
|
||||
def callback(in_data, frame_count, time_info, status):
|
||||
stream = p.open(format=pyaudio.paInt16,
|
||||
channels=2,
|
||||
rate=44100,
|
||||
output=True)
|
||||
|
||||
return (stream_data, pyaudio.paContinue)
|
||||
ffmpeg_process = subprocess.Popen(
|
||||
['ffmpeg', '-i', 'pipe:0', '-f', 'wav', '-ac', '2', '-ar', '44100', '-'],
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
||||
)
|
||||
|
||||
for chunk in r.iter_content(chunk_size=1024):
|
||||
if chunk:
|
||||
# print('b')
|
||||
ffmpeg_process.stdin.write(chunk)
|
||||
|
||||
ffmpeg_process.stdin.close()
|
||||
|
||||
while True:
|
||||
pcm_data = ffmpeg_process.stdout.read(1024)
|
||||
print('a')
|
||||
if not pcm_data:
|
||||
break
|
||||
|
||||
stream.write(pcm_data)
|
||||
|
||||
|
||||
# for chunk in r.iter_content(chunk_size=1024):
|
||||
# if chunk:
|
||||
# ogg_data = io.BytesIO(chunk)
|
||||
# audio = pydub.AudioSegment.from_ogg(ogg_data)
|
||||
# audio = audio.set_sample_width(2)
|
||||
# stream.write(audio.raw_data)
|
||||
|
||||
audio = pyaudio.PyAudio()
|
||||
|
||||
stream = audio.open(format=audio.get_format_from_width(2),
|
||||
channels=2,
|
||||
rate=44100,
|
||||
output=True,
|
||||
stream_callback=callback)
|
||||
|
||||
# r.content.
|
||||
|
||||
# def stream_callback(in_data)
|
||||
# stream.write(audio.raw_data)
|
||||
stream.stop_stream()
|
||||
stream.close()
|
||||
p.terminate()
|
||||
|
||||
ffmpeg_process.wait()
|
||||
|
||||
|
||||
play_song(echidna_id)
|
||||
|
||||
# with open('echidna.xml', 'wb') as file:
|
||||
# file.write(conn.getSong(echidna_id).content)
|
||||
|
||||
# echidna = conn.getSong(echidna_id)
|
||||
|
||||
# print(echidna.title)
|
||||
|
||||
# conn.stream(echidna_id)
|
||||
Reference in new issue
Block a user