本文整理匯總了Python中sounddevice.play方法的典型用法代碼示例。如果您正苦於以下問題:Python sounddevice.play方法的具體用法?Python sounddevice.play怎麽用?Python sounddevice.play使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sounddevice
的用法示例。
在下文中一共展示了sounddevice.play方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def __init__(self, master, fs, mix, sources):
self.master = master
self.fs = fs
self.mix = mix
self.sources = sources
master.title("A simple GUI")
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.mix_button = Button(master, text='Mix', command=lambda: self.play(self.mix))
self.mix_button.pack()
self.buttons = []
for i, source in enumerate(self.sources):
self.buttons.append(Button(master, text='Source ' + str(i+1), command=lambda src=source : self.play(src)))
self.buttons[-1].pack()
self.stop_button = Button(master, text="Stop", command=sd.stop)
self.stop_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
示例2: __init__
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def __init__(self, text, file_name=None, SNR_dB=20, f_code=600, Fs=8000, code_speed=20, length_seconds=4, total_seconds=8, play_sound=True):
self.text = text.upper() # store requested text to be converted in here
self.file_name = file_name # file name to store generated WAV file
self.SNR_dB = SNR_dB # target SNR in dB
self.f_code = f_code # CW tone frequency
self.Fs = Fs # Sampling frequency
self.code_speed = code_speed # code speed in WPM
self.length_seconds = length_seconds # caps the CW generation to this length in seconds
self.total_seconds = total_seconds # pads to the total length if possible
self.play_sound = play_sound # If true, play the generated audio
self.len = self.len_str_in_dits(self.text)
self.morsecode = [] # store audio representation here
self.t = np.linspace(0., 1.2/self.code_speed, num=int(self.Fs*1.2/self.code_speed), endpoint=True, retstep=False)
self.Dit = np.sin(2*np.pi*self.f_code*self.t)
self.ssp = np.zeros(len(self.Dit))
# one Dah of time is 3 times dit time
self.t2 = np.linspace(0., 3*1.2/self.code_speed, num=3*int(self.Fs*1.2/self.code_speed), endpoint=True, retstep=False)
#Dah = np.concatenate((Dit,Dit,Dit))
self.Dah = np.sin(2*np.pi*self.f_code*self.t2)
self.lsp = np.zeros(len(self.Dah))
示例3: __init__
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def __init__(self, text, file_name=None, SNR_dB=20, f_code=600, Fs=8000, code_speed=20, length_seconds=4, total_seconds=8, play_sound=True):
self.text = text.upper() # store requested text to be converted in here
self.file_name = file_name # file name to store generated WAV file
self.SNR_dB = SNR_dB # target SNR in dB
self.f_code = f_code # CW tone frequency
self.Fs = Fs # Sampling frequency
self.code_speed = code_speed # code speed in WPM
self.length_seconds = length_seconds # caps the CW generation to this length in seconds
self.total_seconds = total_seconds # pads to the total length if possible
self.play_sound = play_sound # If true, play the generated audio
self.len = self.len_str_in_dits(self.text)
self.morsecode = [] # store audio representation here
self.t = np.linspace(0., 1.2/self.code_speed, num=int(self.Fs*1.2/self.code_speed), endpoint=True, retstep=False)
self.Dit = np.sin(2*np.pi*self.f_code*self.t)
self.ssp = np.zeros(len(self.Dit))
# one Dah of time is 3 times dit time
self.t2 = np.linspace(0., 3*1.2/self.code_speed, num=3*int(self.Fs*1.2/self.code_speed), endpoint=True, retstep=False)
self.Dah = np.sin(2*np.pi*self.f_code*self.t2)
self.lsp = np.zeros(len(self.Dah))
示例4: preview_wave
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def preview_wave(message, wpm=WPM, frequency=FREQUENCY, framerate=FRAMERATE, amplitude=AMPLITUDE, word_ref=WORD):
"""
Listen (preview) wave
sounddevice is required http://python-sounddevice.readthedocs.org/
$ pip install sounddevice
"""
samp_nb = samples_nb(message=message, wpm=wpm, framerate=framerate, word_spaced=False)
import sounddevice as sd
lst_bin = _encode_binary(message)
amplitude = _limit_value(amplitude)
seconds_per_dot = _seconds_per_dot(word_ref) # 1.2
a = [calculate_wave(i, lst_bin, wpm, frequency, framerate, amplitude, seconds_per_dot)
for i in range(samp_nb)]
sd.play(a, framerate, blocking=True)
示例5: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(self, file_path):
if self.convert:
self.convert_mp3_to_wav(file_path_mp3=file_path)
data, fs = sf.read(file_path)
sd.play(data, fs)
sd.wait()
示例6: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(self, key):
if not self.key_audio_map.get(str(key)):
self.key_audio_map[str(key)] = key % self.non_unique_count
data, fs = self.sound_effect_cache[self.key_audio_map[str(key)]]
data = data * self.configer.volume
fs = fs * self.configer.pitch
threading.Thread(target=sd.play, args=(data, fs)).start()
示例7: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(self, src):
sd.play(pra.normalize(src) * 0.75, samplerate=self.fs, blocking=False)
示例8: __init__
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def __init__(self, master, fs, mix, sources):
self.master = master
self.fs = fs
self.mix = mix
self.sources = sources
master.title("A simple GUI")
self.label = Label(master, text="This is our first GUI!")
self.label.pack()
self.mix_button = Button(
master, text="Mix", command=lambda: self.play(self.mix)
)
self.mix_button.pack()
self.buttons = []
for i, source in enumerate(self.sources):
self.buttons.append(
Button(
master,
text="Source " + str(i + 1),
command=lambda src=source: self.play(src),
)
)
self.buttons[-1].pack()
self.stop_button = Button(master, text="Stop", command=sd.stop)
self.stop_button.pack()
self.close_button = Button(master, text="Close", command=master.quit)
self.close_button.pack()
示例9: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(self, src):
sd.play(pra.normalize(src) * 0.75, samplerate=self.fs, blocking=False)
示例10: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(ch):
sd.play(pra.normalize(y[ch]) * 0.75, samplerate=room.fs, blocking=True)
示例11: play
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play(self):
''' Play the sound sample '''
if have_sounddevice:
sd.play(self.samples, samplerate=self.fs)
else:
print('Warning: sounddevice package is required to play audiofiles.')
示例12: speak
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def speak(self, system_speech):
"""
Takes the system utterance and reads it out. Also can log the audio and text.
Args:
system_speech (np.array): An array of audio that is meant to produce a sound from. The result of the systems TTS synthesis service.
"""
sounddevice.play(system_speech[0], system_speech[1])
# log the utterance
if self.conversation_log_dir is not None:
file_path = os.path.join(self.conversation_log_dir, (str(math.floor(time.time()))))
librosa.output.write_wav(file_path + "_system.wav", system_speech[0], system_speech[1])
with open(file_path + "_system.txt", "w") as convo_log:
convo_log.write(system_speech[2])
示例13: audio
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def audio(self):
"""Generate audio file using other functions"""
self.morsecode = []
self.pad_start()
self.generate_audio()
self.pad_end()
self.SNR()
self.normalize()
if self.play_sound:
sd.play(self.morsecode, self.Fs)
if self.file_name:
write(self.file_name, self.Fs, self.morsecode)
示例14: audio
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def audio(self):
"""Generate audio file using other functions"""
self.morsecode = []
self.pad_start()
self.generate_audio()
self.pad_end()
self.SNR()
self.normalize()
if self.play_sound:
sd.play(self.morsecode, self.Fs)
if self.file_name:
write(self.file_name, self.Fs, self.morsecode)
return self.morsecode
示例15: play_wav
# 需要導入模塊: import sounddevice [as 別名]
# 或者: from sounddevice import play [as 別名]
def play_wav(wav, blocking=True):
try:
import sounddevice as sd
# Small bug with sounddevice.play: the audio is cut 0.5 second too early. We pad it to
# make up for that
wav = np.concatenate((wav, np.zeros(sampling_rate // 2)))
sd.play(wav, sampling_rate, blocking=blocking)
except Exception as e:
print("Failed to play audio: %s" % repr(e))