Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<package>
<name>itf_talk</name>
<version>0.0.0</version>
<version>0.0.2</version>
<description>The itf_talk package</description>

<!-- One maintainer tag required, multiple allowed, one person per tag -->
<!-- Example: -->
<!-- <maintainer email="[email protected]">Jane Doe</maintainer> -->
<maintainer email="alex@todo.todo">alex</maintainer>
<maintainer email="alex@yutani.nl">Alex van der Peet</maintainer>


<!-- One license tag required, multiple allowed, one license per tag -->
Expand Down
2 changes: 1 addition & 1 deletion src/SoundFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@ def __init__(self, filename):
self.gletplayer.set_handler("on_eos", self.stop)

# Load file to pydub, for getting the current power (volume) in the sound file.
self.dubsegment = pydub.AudioSegment.from_mp3(filename)
self.dubsegment = pydub.AudioSegment.from_wav(filename)
32 changes: 23 additions & 9 deletions src/itf_talk.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/usr/bin/env python

import os
import rospy
import urllib, pycurl
from threading import Thread
from std_msgs.msg import String, Float32, Bool
from std_msgs.msg import String, Float64, Bool
import subprocess
import pydub
import math
Expand All @@ -14,17 +15,18 @@
class ITFTalker(Thread):
NODE_NAME = 'itf_talker'
pub = rospy.Publisher('itf_next_sentence', String, queue_size=1)
pub_speech_strength = rospy.Publisher('speech_strength', Float32, queue_size=1)
pub_speech_strength = rospy.Publisher('/dmitry/jaw_controller/command', Float64, queue_size=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be changed back to how it was; its bad to hard code the topic name to produce data for a particular system.

The dmitry jaw controller should instead subscribe to the topic speech_strength.

pub_speech_active = rospy.Publisher('speech_active', Bool, queue_size=1)
soundfile = None
rms_params = {"scale": 1.0/5000, "min": 0.0, "max": 1.0}
gletplayer = None
stop_request_received = False
jaw_inactive = True

def __init__(self):
Thread.__init__(self)
rospy.init_node(ITFTalker.NODE_NAME, log_level=rospy.INFO)
rospy.Subscriber("itf_talk", String, self.callback)
rospy.Subscriber("chatbot_responses", String, self.callback)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be named back as it will break changes with existing code.

The topic would ideally have name like "speech"

E.g. see "speech (std_msgs/String)" on the Nao robot page.

rospy.Subscriber("itf_talk_stop", String, self.callback_stop)

pyglet.clock._get_sleep_time = pyglet.clock.get_sleep_time
Expand Down Expand Up @@ -85,13 +87,15 @@ def speakSpeechFromText(self, phrase):
googleSpeechURL = self.getGoogleSpeechURL(section)
print "Downloading " + googleSpeechURL + " to " + "tts" + str(index).zfill(index) + ".mp3\n"
self.downloadFile(googleSpeechURL,"tts" + str(index).zfill(index) + ".mp3")
fileName = "tts" + str(index).zfill(index)
os.system("avconv -y -i "+fileName+".mp3 "+ fileName+".wav" )
print index, section

totalDuration = 0

for index, section in enumerate(phraseSections):
fileName = 'tts' + str(index).zfill(index) + '.mp3'
dubsegment = pydub.AudioSegment.from_mp3(fileName)
fileName = 'tts' + str(index).zfill(index) + '.wav'
dubsegment = pydub.AudioSegment.from_wav(fileName)
totalDuration += dubsegment.__len__()
dubsegment = None

Expand All @@ -109,9 +113,10 @@ def speakSpeechFromText(self, phrase):
ITFTalker.pub_speech_active.publish(True)

for index, section in enumerate(phraseSections):
fileName = 'tts' + str(index).zfill(index)

fileName = fileName + '.wav'
if (not self.stop_request_received):
fileName = 'tts' + str(index).zfill(index) + '.mp3'
print 'Calling SoundPlayer with parameter ' + fileName

self.play(fileName)

Expand Down Expand Up @@ -142,7 +147,15 @@ def hit(self, rms):
p = self.rms_params
jaw_coeff = min(max(math.sqrt(rms * p["scale"]), p["min"]), p["max"])

self.pub_speech_strength.publish(jaw_coeff)
if jaw_coeff > 0:
jaw_coeff = jaw_coeff*0.4-0.15;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jaw_coeff value, published to speech strength should always be between 0.0 - 1.0. Does this change that? The receiver should alter it to suit their needs.

self.pub_speech_strength.publish(jaw_coeff)
self.jaw_inactive = False
else:
if not self.jaw_inactive:
self.pub_speech_strength.publish(jaw_coeff)
self.jaw_inactive = True


# Copy pau expression message stored during handle_face_in(),
# modify jaw and publish.
Expand All @@ -158,6 +171,7 @@ def stop(self):

def play(self, filename):
self.stop()

self.soundfile = SoundFile(filename)
self.soundfile.on_playmore = self.hit # Set callback
self.soundfile.play()
Expand All @@ -175,7 +189,7 @@ def callback_stop(self, data):
talker = ITFTalker()

talker.start()
rospy.loginfo("{0} started, listening for text input on topic itf_talk...".format(ITFTalker.NODE_NAME))
rospy.loginfo("{0} started, listening for text input on topic chatbot_repsonses...".format(ITFTalker.NODE_NAME))

rospy.spin()

Expand Down