Having the following diagram, how can I amplify output from pin 3&4 to speaker, using BC547 transistor?
Based on the comments and responses, your requirement seems to be:
What you need is an "R-2R" network driven by the two pins. From the diagram you posted:
Connect R15 to Vcc, and R7, R8 and R16 exactly as shown. Keep the values as per the diagram as well, 10k and 20k. Leave out the other resistors in the schematic.
The junction of R16 and R8 will be the DAC output.
This resultant output voltage needs current amplification to drive the speaker:
If distortion of output on the speaker is not a show-stopper, you could make a Common Collector unity gain voltage buffer with your BC547 to generate the speaker output you are expecting. Your speaker will be the load resistor, so no separate resistor is needed there. Your power rail must be able to supply sufficient current for this.
The output will not be a perfect 4-level (i.e. 2-bit) DAC output since we have ignored biasing, but will generate recognizable sound as per the MCU pin values generated.
Common emitter amplifier + Buffer (Emitter follower). If you google these you'll find a site that will tell you how to make them. The common emitter is to amplify the signal and the buffer will simply make sure that the speaker gets most of the signal. Also, don't forget to add caps in between!
Depends on the speaker, and the signal. If it's a piezo, that cct is as loud as it gets without more volts (or a transformer!).
If it's a voice coil, tell us what impedance, and how much power do you want?